mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
Optimize/uniformalize the multibyte filters
This commit is contained in:
committed by
Fabien Potencier
parent
abdee6a8cd
commit
eba8805f4a
+11
-11
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user