[systemd-devel] [PATCH] util: ellipsize_mem: do not print partial utf-8 characters
Shawn Landden
shawn at churchofgit.com
Wed Aug 28 12:36:10 PDT 2013
---
src/shared/util.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/shared/util.c b/src/shared/util.c
index 1dde8af..9af99aa 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3286,7 +3286,7 @@ int running_in_chroot(void) {
}
char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) {
- size_t x;
+ size_t x, j;
char *r;
assert(s);
@@ -3305,13 +3305,20 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
if (x > new_length - 3)
x = new_length - 3;
+ for (;s[x-1] > 127;x--)
+ continue;
+
memcpy(r, s, x);
r[x] = '.';
r[x+1] = '.';
r[x+2] = '.';
+
+ for (j=(x+3);s[j] > 127;j++)
+ continue;
+
memcpy(r + x + 3,
- s + old_length - (new_length - x - 3),
- new_length - x - 3);
+ s + old_length - (new_length - j),
+ new_length - j);
return r;
}
--
1.8.4.rc3
More information about the systemd-devel
mailing list