From: Jordi Boggiano Date: Thu, 21 Oct 2010 18:52:26 +0000 (+0200) Subject: Optimize/uniformalize the multibyte filters X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=eba8805f4a8904565c8b5af8fb52308e79a2ef17;p=web%2Fkonrad%2Ftwig.git Optimize/uniformalize the multibyte filters --- diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index c00c328..ee3afc1 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -291,8 +291,8 @@ if (function_exists('mb_get_info')) { function twig_upper_filter(Twig_Environment $env, $string) { - if (!is_null($env->getCharset())) { - return mb_strtoupper($string, $env->getCharset()); + if (!is_null($charset = $env->getCharset())) { + return mb_strtoupper($string, $charset); } return strtoupper($string); @@ -300,8 +300,8 @@ if (function_exists('mb_get_info')) { function twig_lower_filter(Twig_Environment $env, $string) { - if (!is_null($env->getCharset())) { - return mb_strtolower($string, $env->getCharset()); + if (!is_null($charset = $env->getCharset())) { + return mb_strtolower($string, $charset); } return strtolower($string); @@ -309,21 +309,21 @@ if (function_exists('mb_get_info')) { function twig_title_string_filter(Twig_Environment $env, $string) { - if (is_null($env->getCharset())) { - return ucwords(strtolower($string)); + if (!is_null($charset = $env->getCharset())) { + return mb_convert_case($string, MB_CASE_TITLE, $charset); } - return mb_convert_case($string, MB_CASE_TITLE, $env->getCharset()); + return ucwords(strtolower($string)); } function twig_capitalize_string_filter(Twig_Environment $env, $string) { - if (is_null($env->getCharset())) { - return ucfirst(strtolower($string)); + if (!is_null($charset = $env->getCharset())) { + return mb_strtoupper(mb_substr($string, 0, 1, $charset)). + mb_strtolower(mb_substr($string, 1, mb_strlen($string), $charset), $charset); } - return mb_strtoupper(mb_substr($string, 0, 1, $env->getCharset())). - mb_strtolower(mb_substr($string, 1, mb_strlen($string), $env->getCharset()), $env->getCharset()); + return ucfirst(strtolower($string)); } } // and byte fallback