mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
Merge pull request #32311 from YHNdnzj/write-ellipsis
Some minor cleanup for string-util (ellipsis)
This commit is contained in:
commit
c3d1dbfcdf
@ -11,6 +11,7 @@
|
|||||||
#include "extract-word.h"
|
#include "extract-word.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
|
#include "glyph-util.h"
|
||||||
#include "gunicode.h"
|
#include "gunicode.h"
|
||||||
#include "locale-util.h"
|
#include "locale-util.h"
|
||||||
#include "macro.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) {
|
static int write_ellipsis(char *buf, bool unicode) {
|
||||||
if (unicode || is_locale_utf8()) {
|
const char *s = special_glyph_full(SPECIAL_GLYPH_ELLIPSIS, unicode);
|
||||||
buf[0] = 0xe2; /* tri-dot ellipsis: … */
|
assert(strlen(s) == 3);
|
||||||
buf[1] = 0x80;
|
memcpy(buf, s, 3);
|
||||||
buf[2] = 0xa6;
|
|
||||||
} else {
|
|
||||||
buf[0] = '.';
|
|
||||||
buf[1] = '.';
|
|
||||||
buf[2] = '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,8 +392,7 @@ static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_le
|
|||||||
x = ((new_length - need_space) * percent + 50) / 100;
|
x = ((new_length - need_space) * percent + 50) / 100;
|
||||||
assert(x <= new_length - need_space);
|
assert(x <= new_length - need_space);
|
||||||
|
|
||||||
memcpy(t, s, x);
|
write_ellipsis(mempcpy(t, s, x), /* unicode = */ false);
|
||||||
write_ellipsis(t + x, false);
|
|
||||||
suffix_len = new_length - x - need_space;
|
suffix_len = new_length - x - need_space;
|
||||||
memcpy(t + x + 3, s + old_length - suffix_len, suffix_len);
|
memcpy(t + x + 3, s + old_length - suffix_len, suffix_len);
|
||||||
*(t + x + 3 + suffix_len) = '\0';
|
*(t + x + 3 + suffix_len) = '\0';
|
||||||
@ -520,13 +513,8 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
|
|||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
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);
|
memcpy_safe(e, s, len);
|
||||||
write_ellipsis(e + len, true);
|
write_ellipsis(e + len, /* unicode = */ true);
|
||||||
|
|
||||||
char *dst = e + len + 3;
|
char *dst = e + len + 3;
|
||||||
|
|
||||||
@ -605,7 +593,7 @@ char *cellescape(char *buf, size_t len, const char *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i + 4 <= len) /* yay, enough space */
|
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 ".." */
|
else if (i + 3 <= len) { /* only space for ".." */
|
||||||
buf[i++] = '.';
|
buf[i++] = '.';
|
||||||
buf[i++] = '.';
|
buf[i++] = '.';
|
||||||
|
@ -38,11 +38,12 @@ int parse_show_status(const char *v, ShowStatus *ret) {
|
|||||||
|
|
||||||
int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) {
|
int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) {
|
||||||
static const char status_indent[] = " "; /* "[" STATUS "] " */
|
static const char status_indent[] = " "; /* "[" STATUS "] " */
|
||||||
|
static bool prev_ephemeral = false;
|
||||||
|
|
||||||
_cleanup_free_ char *s = NULL;
|
_cleanup_free_ char *s = NULL;
|
||||||
_cleanup_close_ int fd = -EBADF;
|
_cleanup_close_ int fd = -EBADF;
|
||||||
struct iovec iovec[7] = {};
|
struct iovec iovec[7] = {};
|
||||||
int n = 0;
|
int n = 0;
|
||||||
static bool prev_ephemeral;
|
|
||||||
|
|
||||||
assert(format);
|
assert(format);
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ int status_vprintf(const char *status, ShowStatusFlags flags, const char *format
|
|||||||
if (c <= 0)
|
if (c <= 0)
|
||||||
c = 80;
|
c = 80;
|
||||||
|
|
||||||
sl = status ? sizeof(status_indent)-1 : 0;
|
sl = status ? strlen(status_indent) : 0;
|
||||||
|
|
||||||
emax = c - sl - 1;
|
emax = c - sl - 1;
|
||||||
if (emax < 3)
|
if (emax < 3)
|
||||||
|
Loading…
Reference in New Issue
Block a user