From eba8805f4a8904565c8b5af8fb52308e79a2ef17 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 21 Oct 2010 20:52:26 +0200 Subject: [PATCH] Optimize/uniformalize the multibyte filters --- lib/Twig/Extension/Core.php | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-) 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 -- 1.7.2.5