summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/unicode.inc6
1 files changed, 5 insertions, 1 deletions
diff --git a/includes/unicode.inc b/includes/unicode.inc
index 54fe7bb8b..cd8285514 100644
--- a/includes/unicode.inc
+++ b/includes/unicode.inc
@@ -193,12 +193,16 @@ function truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE) {
return $string;
}
if ($wordsafe) {
+ $end = $len;
while (($string[--$len] != ' ') && ($len > 0)) {};
+ if ($len == 0) {
+ $len = $end;
+ }
}
if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
return substr($string, 0, $len) . ($dots ? ' ...' : '');
}
- while (ord($string[--$len]) < 0xC0) {};
+ while (--$len >= 0 && ord($string[$len]) >= 0x80 && ord($string[$len]) < 0xC0) {};
return substr($string, 0, $len) . ($dots ? ' ...' : '');
}