[drupal-devel] [feature] New API function: truncate_utf8_conc
Goba
drupal-devel at drupal.org
Fri Apr 29 18:03:50 UTC 2005
Issue status update for http://drupal.org/node/21576
Project: Drupal
Version: cvs
Component: base system
Category: feature requests
Priority: normal
Assigned to: Bèr Kessels
Reported by: Bèr Kessels
Updated by: Goba
Status: patch
My first thought was that this should be integrated into truncate_utf8()
and I still think so. Having a separate function seems to be inadequate
to me. Also noticed that truncate_utf8() - and as a result, this
suggested function - is broken in that the passed length is not
properly used. If you have multibyte characters in the string, strlen()
will not return the number of chars but the number of bytes used to
represent them (except if you have mbstring overrides, but that is not
common).
Goba
Previous comments:
------------------------------------------------------------------------
April 29, 2005 - 11:46 : Bèr Kessels
Attachment: http://drupal.org/files/issues/common_inc_truncate_utf8_conc.diff (1.63 KB)
This function truncates the string, but adds a string to the end, when
requested. For example to concenate three dots (...) to a long
username.
For example to turn the long username
* johndoe at www.personalweblog.com into johndoe at www.johndo...
Its possible with the current truncate_utf8(), but than you need to do
string comparison and some more truncation afterwards, which is not
optimal.
And please mark this as wontfix if not appropriate. I do not have time
to maintain this patch, so if its not up to standards or so, just close
this issue.
------------------------------------------------------------------------
April 29, 2005 - 15:36 : Dries
You can update existing code (e.g. like format_name()) to take advantage
of this patch:
$ grep -r "truncate_utf8" * | grep '\.\.\.'
includes/common.inc: $name = truncate_utf8($object->name, 15)
.'...';
modules/search.module: return truncate_utf8($text, 256) . ' ...';
Also, $conc is not very descriptive as variable name. Maybe call is
$postfix instead?
------------------------------------------------------------------------
April 29, 2005 - 15:52 : Bèr Kessels
Attachment: http://drupal.org/files/issues/common_inc_truncate_utf8_conc_0.diff (2.82 KB)
I updated the function to use the better name $postfix. Also, I changed
the two places where these three dots were appended in a custom way.
More information about the drupal-devel
mailing list