Fix issue 785.

This commit is contained in:
Thomas Keller 2012-02-24 01:29:25 +01:00
parent c0506c460d
commit 9bd5912884
2 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,9 @@
## Bugfixes ## Bugfixes
- Ensure that IDF does not break UTF-8 encoded strings when
shortening them for view rendering (issue 785)
## Documentation ## Documentation
## Translations ## Translations

View File

@ -506,12 +506,12 @@ function IDF_Views_Source_PrettySizeSimple($size)
function IDF_Views_Source_ShortenString($string, $length) function IDF_Views_Source_ShortenString($string, $length)
{ {
$ellipse = "..."; $ellipse = "...";
$length = max(strlen($ellipse) + 2, $length); $length = max(mb_strlen($ellipse) + 2, $length);
$preflen = ceil($length / 10); $preflen = ceil($length / 10);
if (mb_strlen($string) < $length) if (mb_strlen($string) < $length)
return $string; return $string;
return substr($string, 0, $preflen).$ellipse. return mb_substr($string, 0, $preflen).$ellipse.
substr($string, -($length - $preflen - mb_strlen($ellipse))); mb_substr($string, -($length - $preflen - mb_strlen($ellipse)));
} }