Skip to content
Snippets Groups Projects
Commit 2c2d981e authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Optionally show dots after truncation. TODO: update user.module to take advantage of this.

parent 02460ed9
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -1831,7 +1831,7 @@ function drupal_convert_to_utf8($data, $encoding) { ...@@ -1831,7 +1831,7 @@ function drupal_convert_to_utf8($data, $encoding) {
* @return * @return
* The truncated string. * The truncated string.
*/ */
function truncate_utf8($string, $len, $wordsafe = FALSE) { function truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE) {
$slen = strlen($string); $slen = strlen($string);
if ($slen <= $len) { if ($slen <= $len) {
return $string; return $string;
...@@ -1840,10 +1840,10 @@ function truncate_utf8($string, $len, $wordsafe = FALSE) { ...@@ -1840,10 +1840,10 @@ function truncate_utf8($string, $len, $wordsafe = FALSE) {
while (($string[--$len] != ' ') && ($len > 0)) {}; while (($string[--$len] != ' ') && ($len > 0)) {};
} }
if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) { if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
return substr($string, 0, $len); return substr($string, 0, $len) . ($dots ? ' ...' : '');
} }
while (ord($string[--$len]) < 0xC0) {}; while (ord($string[--$len]) < 0xC0) {};
return substr($string, 0, $len); return substr($string, 0, $len) . ($dots ? ' ...' : '');
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment