From 35a405beacfe401c7d6c1ffd9a1249970478b932 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 18 Feb 2010 17:40:16 +0100 Subject: [PATCH] fixed twig_length_filter (closes #14) --- lib/Twig/Extension/Core.php | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index b24b6c4..7e7902d 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -172,11 +172,6 @@ function twig_is_odd_filter($value) return $value % 2 == 1; } -function twig_length_filter($thing) -{ - return is_string($thing) ? strlen($thing) : count($thing); -} - function twig_sort_filter($array) { asort($array); @@ -242,6 +237,11 @@ function twig_escape_filter(Twig_Environment $env, $string, $type = 'html') // add multibyte extensions if possible if (function_exists('mb_get_info')) { + function twig_length_filter($thing) + { + return is_string($thing) ? mb_strlen($thing, $env->getCharset()) : count($thing); + } + function twig_upper_filter(Twig_Environment $env, $string) { if (!is_null($env->getCharset())) @@ -286,6 +286,11 @@ if (function_exists('mb_get_info')) // and byte fallback else { + function twig_length_filter($thing) + { + return is_string($thing) ? strlen($thing) : count($thing); + } + function twig_title_string_filter(Twig_Environment $env, $string) { return ucwords(strtolower($string)); -- 1.7.2.5