summaryrefslogtreecommitdiffstats
path: root/src/basic/string-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-04-17 03:01:39 +0200
committerMike Yuan <me@yhndnzj.com>2024-04-17 11:03:49 +0200
commitd723363a86fa9bd6cd1cf0e30f7a82432fb0bd1c (patch)
tree9400f97bbbff9527f6b907371fc7b49d5b4aa555 /src/basic/string-util.c
parentfuzz-ndisc-rs: also test packets with sd-radv (diff)
downloadsystemd-d723363a86fa9bd6cd1cf0e30f7a82432fb0bd1c.tar.xz
systemd-d723363a86fa9bd6cd1cf0e30f7a82432fb0bd1c.zip
string-util: use special_glyph() at one more place
No functional change, just refactoring.
Diffstat (limited to 'src/basic/string-util.c')
-rw-r--r--src/basic/string-util.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index e775326e29..0a108f4b11 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -11,6 +11,7 @@
#include "extract-word.h"
#include "fd-util.h"
#include "fileio.h"
+#include "glyph-util.h"
#include "gunicode.h"
#include "locale-util.h"
#include "macro.h"
@@ -282,16 +283,9 @@ bool string_has_cc(const char *p, const char *ok) {
}
static int write_ellipsis(char *buf, bool unicode) {
- if (unicode || is_locale_utf8()) {
- buf[0] = 0xe2; /* tri-dot ellipsis: … */
- buf[1] = 0x80;
- buf[2] = 0xa6;
- } else {
- buf[0] = '.';
- buf[1] = '.';
- buf[2] = '.';
- }
-
+ const char *s = special_glyph_full(SPECIAL_GLYPH_ELLIPSIS, unicode);
+ assert(strlen(s) == 3);
+ memcpy(buf, s, 3);
return 3;
}
@@ -399,7 +393,7 @@ static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_le
assert(x <= new_length - need_space);
memcpy(t, s, x);
- write_ellipsis(t + x, false);
+ write_ellipsis(t + x, /* unicode = */ false);
suffix_len = new_length - x - need_space;
memcpy(t + x + 3, s + old_length - suffix_len, suffix_len);
*(t + x + 3 + suffix_len) = '\0';
@@ -520,13 +514,8 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
if (!e)
return NULL;
- /*
- printf("old_length=%zu new_length=%zu x=%zu len=%zu len2=%zu k=%zu\n",
- old_length, new_length, x, len, len2, k);
- */
-
memcpy_safe(e, s, len);
- write_ellipsis(e + len, true);
+ write_ellipsis(e + len, /* unicode = */ true);
char *dst = e + len + 3;
@@ -605,7 +594,7 @@ char *cellescape(char *buf, size_t len, const char *s) {
}
if (i + 4 <= len) /* yay, enough space */
- i += write_ellipsis(buf + i, false);
+ i += write_ellipsis(buf + i, /* unicode = */ false);
else if (i + 3 <= len) { /* only space for ".." */
buf[i++] = '.';
buf[i++] = '.';