diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-05 12:41:25 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-05 13:59:23 +0200 |
commit | b19f211698f2359464bd46c69a45390b6579b705 (patch) | |
tree | 1f34b780978c5a8b0d46ab6e93bd82627850f674 /src/basic/escape.c | |
parent | d12ccbc30252935b13bc2d4da51b55b096154afb (diff) | |
download | systemd-b19f211698f2359464bd46c69a45390b6579b705.tar.gz |
basic/escape: flagsify xescape_full()
Diffstat (limited to 'src/basic/escape.c')
-rw-r--r-- | src/basic/escape.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/basic/escape.c b/src/basic/escape.c index 45899b6b7c..f579f15d87 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -360,13 +360,13 @@ int cunescape_length_with_prefix(const char *s, size_t length, const char *prefi return t - r; } -char* xescape_full(const char *s, const char *bad, size_t console_width, bool eight_bits) { +char* xescape_full(const char *s, const char *bad, size_t console_width, XEscapeFlags flags) { char *ans, *t, *prev, *prev2; const char *f; /* Escapes all chars in bad, in addition to \ and all special chars, in \xFF style escaping. May be - * reversed with cunescape(). If eight_bits is true, characters >= 127 are let through unchanged. - * This corresponds to non-ASCII printable characters in pre-unicode encodings. + * reversed with cunescape(). If XESCAPE_8_BIT is specified, characters >= 127 are let through + * unchanged. This corresponds to non-ASCII printable characters in pre-unicode encodings. * * If console_width is reached, output is truncated and "..." is appended. */ @@ -388,7 +388,8 @@ char* xescape_full(const char *s, const char *bad, size_t console_width, bool ei return ans; } - if ((unsigned char) *f < ' ' || (!eight_bits && (unsigned char) *f >= 127) || + if ((unsigned char) *f < ' ' || + (!FLAGS_SET(flags, XESCAPE_8_BIT) && (unsigned char) *f >= 127) || *f == '\\' || strchr(bad, *f)) { if ((size_t) (t - ans) + 4 > console_width) break; @@ -427,9 +428,9 @@ char* xescape_full(const char *s, const char *bad, size_t console_width, bool ei return ans; } -char* escape_non_printable_full(const char *str, size_t console_width, bool eight_bit) { - if (eight_bit) - return xescape_full(str, "", console_width, true); +char* escape_non_printable_full(const char *str, size_t console_width, XEscapeFlags flags) { + if (FLAGS_SET(flags, XESCAPE_8_BIT)) + return xescape_full(str, "", console_width, flags); else return utf8_escape_non_printable_full(str, console_width); } |