- bugfix the truncate modifier needs to check if the string is utf-8 encoded or not

This commit is contained in:
Uwe.Tews
2010-07-07 16:34:06 +00:00
parent c83ef6792c
commit c8f22fe247
2 changed files with 51 additions and 45 deletions

View File

@@ -1,3 +1,6 @@
07/07/2010
- bugfix the truncate modifier needs to check if the string is utf-8 encoded or not
06/07/2010
- create exception on recursive {extends} calls
- fixed reported line number at "unexpected closing tag " exception

View File

@@ -31,6 +31,8 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...',
return '';
if (is_callable('mb_strlen')) {
if (mb_detect_encoding($text, 'UTF-8, ISO-8859-1') === 'UTF-8') {
// $string has utf-8 encoding
if (mb_strlen($string) > $length) {
$length -= min($length, mb_strlen($etc));
if (!$break_words && !$middle) {
@@ -44,7 +46,9 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...',
} else {
return $string;
}
} else {
}
}
// $string has utf-8 no encoding
if (strlen($string) > $length) {
$length -= min($length, strlen($etc));
if (!$break_words && !$middle) {
@@ -59,6 +63,5 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...',
return $string;
}
}
}
?>