Index: includes/locale.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/locale.inc,v retrieving revision 1.178 diff -u -p -r1.178 locale.inc --- includes/locale.inc 22 Jul 2008 20:03:41 -0000 1.178 +++ includes/locale.inc 28 Jul 2008 13:55:18 -0000 @@ -1982,7 +1982,7 @@ function _locale_translate_seek() { foreach ($arr as $lid => $value) { $rows[] = array( $value['group'], - array('data' => check_plain(truncate_utf8($value['source'], 150, FALSE, TRUE)) . '
' . $value['location'] . ''), + array('data' => check_plain(drupal_truncate_chars($value['source'], 150, FALSE, TRUE)) . '
' . $value['location'] . ''), array('data' => _locale_translate_language_list($value['languages'], $limit_language), 'align' => 'center'), array('data' => l(t('edit'), "admin/build/translate/edit/$lid"), 'class' => 'nowrap'), array('data' => l(t('delete'), "admin/build/translate/delete/$lid"), 'class' => 'nowrap'), Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.430 diff -u -p -r1.430 theme.inc --- includes/theme.inc 11 Jul 2008 02:23:08 -0000 1.430 +++ includes/theme.inc 28 Jul 2008 13:55:19 -0000 @@ -1622,12 +1622,7 @@ function theme_username($object) { if ($object->uid && $object->name) { // Shorten the name when it is too long or it will break many tables. - if (drupal_strlen($object->name) > 20) { - $name = drupal_substr($object->name, 0, 15) . '...'; - } - else { - $name = $object->name; - } + $name = drupal_truncate_chars($object->name, 20, FALSE, TRUE); if (user_access('access user profiles')) { $output = l($name, 'user/' . $object->uid, array('attributes' => array('title' => t('View user profile.')))); Index: includes/unicode.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/unicode.inc,v retrieving revision 1.31 diff -u -p -r1.31 unicode.inc --- includes/unicode.inc 18 Jun 2008 03:36:23 -0000 1.31 +++ includes/unicode.inc 28 Jul 2008 13:55:19 -0000 @@ -196,8 +196,8 @@ function drupal_convert_to_utf8($data, $ * * Use this function whenever you want to chop off a string at an unsure * location. On the other hand, if you're sure that you're splitting on a - * character boundary (e.g. after using strpos() or similar), you can safely use - * substr() instead. + * character boundary (e.g. after using drupal_strlen() or similar), you can + * safely use drupal_truncate_chars() instead. * * @param $string * The string to truncate. @@ -231,17 +231,17 @@ function drupal_truncate_bytes($string, * @return * The truncated string. */ -function truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE) { +function drupal_truncate_chars($string, $len, $wordsafe = FALSE, $dots = FALSE) { if (drupal_strlen($string) <= $len) { return $string; } - if ($dots) { - $len -= 4; - } - if ($wordsafe) { + if ($dots) { + // Make room for ' ...' if needed. + $len -= 4; + } $string = drupal_substr($string, 0, $len + 1); // leave one more character if ($last_space = strrpos($string, ' ')) { // space exists AND is not on position 0 $string = substr($string, 0, $last_space); @@ -249,15 +249,18 @@ function truncate_utf8($string, $len, $w else { $string = drupal_substr($string, 0, $len); } + if ($dots) { + $string .= ' ...'; + } + } + elseif ($dots) { + $len -= 3; // Make room for '...' + $string = drupal_substr($string, 0, $len) . '...'; } else { $string = drupal_substr($string, 0, $len); } - if ($dots) { - $string .= ' ...'; - } - return $string; } @@ -271,8 +274,8 @@ function truncate_utf8($string, $len, $w * * Notes: * - Only encode strings that contain non-ASCII characters. - * - We progressively cut-off a chunk with truncate_utf8(). This is to ensure - * each chunk starts and ends on a character boundary. + * - We progressively cut-off a chunk with truncate_truncate_bytes(). This is to + * ensure each chunk starts and ends on a byte boundary. * - Using \n as the chunk separator may cause problems on some systems and may * have to be changed to \r\n or \r. */ Index: modules/aggregator/aggregator.module =================================================================== RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.module,v retrieving revision 1.382 diff -u -p -r1.382 aggregator.module --- modules/aggregator/aggregator.module 5 Jul 2008 05:57:00 -0000 1.382 +++ modules/aggregator/aggregator.module 28 Jul 2008 13:55:19 -0000 @@ -724,7 +724,7 @@ function aggregator_parse_feed(&$data, $ $title = $item['TITLE']; } elseif (!empty($item['DESCRIPTION'])) { - $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 40)); + $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", drupal_truncate_chars($item['DESCRIPTION'], 40)); } else { $title = ''; Index: modules/book/book.module =================================================================== RCS file: /cvs/drupal/drupal/modules/book/book.module,v retrieving revision 1.467 diff -u -p -r1.467 book.module --- modules/book/book.module 16 Jul 2008 21:59:26 -0000 1.467 +++ modules/book/book.module 28 Jul 2008 13:55:19 -0000 @@ -872,7 +872,7 @@ function _book_toc_recurse($tree, $inden } if (!in_array($data['link']['mlid'], $exclude)) { - $toc[$data['link']['mlid']] = $indent . ' ' . truncate_utf8($data['link']['title'], 30, TRUE, TRUE); + $toc[$data['link']['mlid']] = $indent . ' ' . drupal_truncate_chars($data['link']['title'], 30, TRUE, TRUE); if ($data['below']) { _book_toc_recurse($data['below'], $indent . '--', $toc, $exclude, $depth_limit); } Index: modules/comment/comment.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.admin.inc,v retrieving revision 1.10 diff -u -p -r1.10 comment.admin.inc --- modules/comment/comment.admin.inc 16 Jul 2008 21:59:26 -0000 1.10 +++ modules/comment/comment.admin.inc 28 Jul 2008 13:55:19 -0000 @@ -76,7 +76,7 @@ function comment_admin_overview($type = $comments[$comment->cid] = ''; $comment->name = $comment->uid ? $comment->registered_name : $comment->name; $form['subject'][$comment->cid] = array( - '#markup' => l($comment->subject, 'node/' . $comment->nid, array('attributes' => array('title' => truncate_utf8($comment->comment, 128)), 'fragment' => 'comment-' . $comment->cid)) + '#markup' => l($comment->subject, 'node/' . $comment->nid, array('attributes' => array('title' => drupal_truncate_chars($comment->comment, 128)), 'fragment' => 'comment-' . $comment->cid)) ); $form['username'][$comment->cid] = array( '#markup' => theme('username', $comment) Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.643 diff -u -p -r1.643 comment.module --- modules/comment/comment.module 16 Jul 2008 21:59:26 -0000 1.643 +++ modules/comment/comment.module 28 Jul 2008 13:55:19 -0000 @@ -1522,7 +1522,7 @@ function _comment_form_submit(&$comment_ // 2) Strip out all HTML tags // 3) Convert entities back to plain-text. // Note: format is checked by check_markup(). - $comment_values['subject'] = trim(truncate_utf8(decode_entities(strip_tags(check_markup($comment_values['comment'], $comment_values['format']))), 29, TRUE)); + $comment_values['subject'] = trim(drupal_truncate_chars(decode_entities(strip_tags(check_markup($comment_values['comment'], $comment_values['format']))), 29, TRUE)); // Edge cases where the comment body is populated only by HTML tags will // require a default subject. if ($comment_values['subject'] == '') { Index: modules/dblog/dblog.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/dblog/dblog.admin.inc,v retrieving revision 1.8 diff -u -p -r1.8 dblog.admin.inc --- modules/dblog/dblog.admin.inc 19 Jul 2008 07:44:45 -0000 1.8 +++ modules/dblog/dblog.admin.inc 28 Jul 2008 13:55:19 -0000 @@ -78,7 +78,7 @@ function dblog_overview() { $icons[$dblog->severity], t($dblog->type), format_date($dblog->timestamp, 'small'), - l(truncate_utf8(_dblog_format_message($dblog), 56, TRUE, TRUE), 'admin/reports/event/' . $dblog->wid, array('html' => TRUE)), + l(drupal_truncate_chars(_dblog_format_message($dblog), 56, TRUE, TRUE), 'admin/reports/event/' . $dblog->wid, array('html' => TRUE)), theme('username', $dblog), $dblog->link, ), @@ -112,7 +112,7 @@ function dblog_top($type) { $rows = array(); while ($dblog = db_fetch_object($result)) { - $rows[] = array($dblog->count, truncate_utf8(_dblog_format_message($dblog), 56, TRUE, TRUE)); + $rows[] = array($dblog->count, drupal_truncate_chars(_dblog_format_message($dblog), 56, TRUE, TRUE)); } if (empty($rows)) { Index: modules/filter/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v retrieving revision 1.217 diff -u -p -r1.217 filter.module --- modules/filter/filter.module 24 Jul 2008 16:25:17 -0000 1.217 +++ modules/filter/filter.module 28 Jul 2008 13:55:19 -0000 @@ -839,12 +839,7 @@ function _filter_url_trim($text, $length $_length = $length; } - // Use +3 for '...' string length. - if (strlen($text) > $_length + 3) { - $text = substr($text, 0, $_length) . '...'; - } - - return $text; + return drupal_truncate_chars($text, $_length, FALSE, TRUE); } /** Index: modules/menu/menu.module =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v retrieving revision 1.166 diff -u -p -r1.166 menu.module --- modules/menu/menu.module 24 Jul 2008 16:25:18 -0000 1.166 +++ modules/menu/menu.module 28 Jul 2008 13:55:19 -0000 @@ -226,7 +226,7 @@ function _menu_parents_recurse($tree, $m break; } if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >= 0) { - $title = $indent . ' ' . truncate_utf8($data['link']['title'], 30, TRUE, FALSE); + $title = $indent . ' ' . drupal_truncate_chars($data['link']['title'], 30, TRUE, FALSE); if ($data['link']['hidden']) { $title .= ' (' . t('disabled') . ')'; } Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.969 diff -u -p -r1.969 node.module --- modules/node/node.module 24 Jul 2008 16:25:18 -0000 1.969 +++ modules/node/node.module 28 Jul 2008 13:55:20 -0000 @@ -365,7 +365,7 @@ function node_teaser($body, $format = NU // sentence boundaries. // The teaser may not be longer than maximum length specified. Initial slice. - $teaser = truncate_utf8($body, $size); + $teaser = drupal_truncate_chars($body, $size); // Store the actual length of the UTF8 string -- which might not be the same // as $size. Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.260 diff -u -p -r1.260 search.module --- modules/search/search.module 24 Jul 2008 16:25:18 -0000 1.260 +++ modules/search/search.module 28 Jul 2008 13:55:20 -0000 @@ -390,7 +390,7 @@ function search_index_split($text) { * Helper function for array_walk in search_index_split. */ function _search_index_truncate(&$text) { - $text = truncate_utf8($text, 50); + $text = drupal_truncate_chars($text, 50); } /** @@ -1230,7 +1230,7 @@ function search_excerpt($keys, $text) { // If we didn't find anything, return the beginning. if (count($ranges) == 0) { - return truncate_utf8($text, 256) . ' ...'; + return drupal_truncate_chars($text, 256) . ' ...'; } // Sort the text ranges by starting position. Index: modules/statistics/statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v retrieving revision 1.279 diff -u -p -r1.279 statistics.module --- modules/statistics/statistics.module 12 Jun 2008 18:46:51 -0000 1.279 +++ modules/statistics/statistics.module 28 Jul 2008 13:55:20 -0000 @@ -293,7 +293,7 @@ function statistics_block($op = 'list', */ function _statistics_link($path, $width = 35) { $title = drupal_get_path_alias($path); - $title = truncate_utf8($title, $width, FALSE, TRUE); + $title = drupal_truncate_chars($title, $width, FALSE, TRUE); return l($title, $path); }