aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-12 04:01:52 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-12 04:01:52 +0000
commitc9b9a9c78db9aa9bf62d5924d6739519945f209c (patch)
treef82a686d3bd15952bf3bcc58cb7dbe174a410adb
parent307d8c9d5c0568c4294487d26c25450968ed28cf (diff)
downloadelgg-c9b9a9c78db9aa9bf62d5924d6739519945f209c.tar.gz
elgg-c9b9a9c78db9aa9bf62d5924d6739519945f209c.tar.bz2
Wrapped all multibyte functions that are directly interchangable with non mb functions with elgg_*().
git-svn-id: http://code.elgg.org/elgg/trunk@3670 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/mb_wrapper.php85
1 files changed, 34 insertions, 51 deletions
diff --git a/engine/lib/mb_wrapper.php b/engine/lib/mb_wrapper.php
index 2cef15c64..7d49da315 100644
--- a/engine/lib/mb_wrapper.php
+++ b/engine/lib/mb_wrapper.php
@@ -1,61 +1,44 @@
<?php
-/**
- * Elgg wrapper functions for multibyte string support.
- *
- * @package Elgg
- * @subpackage Core
- * @author Curverider Ltd
- * @link http://elgg.org/
- */
-/**
- * Wrapper function: Returns the result of mb_strtolower if mb_support is present, else the
- * result of strtolower is returned.
- *
- * @param string $string The string.
- * @param string $charset The charset (if multibyte support is present) : default 'UTF8'
- * @return string
- */
-function elgg_strtolower($string, $charset = 'UTF8') {
- if (is_callable('mb_strtolower')) {
- return mb_strtolower($string, $charset);
- }
-
- return strtolower($string);
+// if mb functions are available, set internal encoding to UTF8
+if (is_callable('mb_internal_encoding')) {
+ mb_internal_encoding("UTF-8");
}
-/**
- * Wrapper function: Returns the result of mb_strtoupper if mb_support is present, else the
- * result of strtoupper is returned.
- *
- * @param string $string The string.
- * @param string $charset The charset (if multibyte support is present) : default 'UTF8'
- * @return string
- */
-function elgg_strtoupper($string, $charset = 'UTF8') {
- if (is_callable('mb_strtoupper')) {
- return mb_strtoupper($string, $charset);
- }
+// map string functions to their mb_str_func alternatives
+// and wrap them in elgg_str_fun()
- return strtoupper($string);
-}
+// list of non-mb safe string functions to wrap in elgg_*()
+// only will work with mb_* functions that take the same
+// params in the same order as their non-mb safe counterparts.
+$str_funcs = array(
+ 'parse_str',
+ 'split',
+ 'stristr',
+ 'strlen',
+ 'strpos',
+ 'strrchr',
+ 'strripos',
+ 'strrpos',
+ 'strstr',
+ 'strtolower',
+ 'strtoupper',
+ 'substr_count',
+ 'substr'
+);
-/**
- * Wrapper function: Returns the result of mb_substr if mb_support is present, else the
- * result of substr is returned.
- *
- * @param string $string The string.
- * @param int $start Start position.
- * @param int $length Length.
- * @param string $charset The charset (if multibyte support is present) : default 'UTF8'
- * @return string
- */
-function elgg_substr($string, $start = 0, $length = null, $charset = 'UTF8') {
- if (is_callable('mb_substr')) {
- return mb_substr($string, $start, $length, $charset);
+$eval_statement = '';
+foreach ($str_funcs as $func) {
+ // create wrapper function passing in the same args as given
+ $eval_statement .= "
+ function elgg_$func() {
+ \$args = func_get_args();
+ if (is_callable('$mb_func')) {
+ return call_user_func_array('$mb_func', \$args);
+ }
+ return call_user_func_array('$func', \$args);
}
-
- return substr($string, $start, $length);
+";
}
// TODO: Other wrapper functions \ No newline at end of file