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. */
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;
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);
}
}
int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit, bool accept_nul);
-char* xescape_full(const char *s, const char *bad, size_t console_width, bool eight_bits);
+typedef enum XEscapeFlags {
+ XESCAPE_8_BIT = 1 << 0,
+} XEscapeFlags;
+
+char* xescape_full(const char *s, const char *bad, size_t console_width, XEscapeFlags flags);
static inline char* xescape(const char *s, const char *bad) {
- return xescape_full(s, bad, SIZE_MAX, false);
+ return xescape_full(s, bad, SIZE_MAX, 0);
}
char* octescape(const char *s, size_t len);
-char* escape_non_printable_full(const char *str, size_t console_width, bool eight_bit);
+char* escape_non_printable_full(const char *str, size_t console_width, XEscapeFlags flags);
char* shell_escape(const char *s, const char *bad);
char* shell_maybe_quote(const char *s, ShellEscapeFlags flags);
bool eight_bit = (flags & PROCESS_CMDLINE_USE_LOCALE) && !is_locale_utf8();
- ans = escape_non_printable_full(t, max_columns, eight_bit);
+ ans = escape_non_printable_full(t, max_columns, eight_bit * XESCAPE_8_BIT);
if (!ans)
return -ENOMEM;
"a\\x62c\\x5c\"\\x08\\x0c\\x0a\\x0d\\x09\\x0b\\x07\\x03\\x7f\\x9c\\xcb" :
"a\\x62c\\x5c\"\\x08\\x0c\\x0a\\x0d\\x09\\x0b\\x07\\x03\177\234\313";
const unsigned full_fit = !eight_bits ? 55 : 46;
+ XEscapeFlags flags = eight_bits * XESCAPE_8_BIT;
for (unsigned i = 0; i < 60; i++) {
_cleanup_free_ char *t;
- assert_se(t = xescape_full("abc\\\"\b\f\n\r\t\v\a\003\177\234\313", "b", i, eight_bits));
+ assert_se(t = xescape_full("abc\\\"\b\f\n\r\t\v\a\003\177\234\313", "b", i, flags));
log_info("%02d: %s", i, t);