Index: common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.438
diff -u -F^f -r1.438 common.inc
--- common.inc	28 Apr 2005 19:23:19 -0000	1.438
+++ common.inc	29 Apr 2005 10:56:41 -0000
@@ -1716,6 +1716,37 @@ function truncate_utf8($string, $len, $w
 }
 
 /**
+ * Truncate a UTF-8-encoded string safely and append it with a string, if truncated.
+ *
+ * If the end position is in the middle of a UTF-8 sequence, it scans backwards
+ * until the beginning of the byte sequence.
+ *
+ * Use this function whenever you want to chop off a string at an unsure
+ * location, and want to append it with a string. For example to turn the long username
+ * johndoe@www.personalweblog.com into johndoe@www.johndo...
+ *
+ * @param $string
+ *   The string to truncate.
+ * @param $len
+ *   An upper limit on the returned string length.
+ * @param $conc
+ *   string to append to the trunkated string. Defaults to "..."
+ * @return
+ *   The truncated string.
+ */
+function truncate_utf8_conc($string, $len, $conc = '...') { 
+  //return non truncated, when smaller then $len plus the amount of chars to be concenated.
+  if (strlen($string) <= ($len + strlen($conc))) {
+    return $string;
+}
+  if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
+    return substr($string, 0, $len) . '...';
+}
+  while (ord($string[--$len]) < 0xC0) {};
+  return substr($string, 0, $len) . '...';
+}
+
+/**
  * Encodes MIME/HTTP header values that contain non US-ASCII characters.
  *
  * For example, mime_header_encode('tést.txt') returns "=?UTF-8?B?dMOpc3QudHh0?=".
