[systemd-devel] [PATCH 2/3] util, utf8: new wellipsize and wellipsize_mem that take into account multi-byte characters

Shawn Landden shawn at churchofgit.com
Wed Sep 11 07:47:38 PDT 2013


This version counts all multibyte characters as 1 width, not taking into
account double width cjk characters and zerowidth characters
---
 src/shared/util.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index b791433..c6375e5 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3310,14 +3310,14 @@ char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, u
                 continue;
 
         memcpy(r, s, x);
-        r[x] = '.';
-        r[x+1] = '.';
-        r[x+2] = '.';
+        r[x] = 0xe2;
+        r[x+1] = 0x80;
+        r[x+2] = 0xa6;
 
         for (j=(x+3);(unsigned char)s[j] & 0x80;j++)
                 continue;
 
-        memcpy(r + x + 3,
+        memcpy(r + x + 1,
                s + old_length - (new_length - j),
                new_length - j);
 
-- 
1.8.4.rc3



More information about the systemd-devel mailing list