diff options
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/mb_wrapper.php | 85 |
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 |