wsutil: Add more character escapes to ws_escape_string()

Add whitespace and other escapes for a better display of strings
in the UI.
This commit is contained in:
João Valverde 2021-11-29 16:02:40 +00:00 committed by Wireshark GitLab Utility
parent 54bdc20e45
commit 9c61142195
2 changed files with 13 additions and 2 deletions

View File

@ -271,6 +271,13 @@ static inline char
escape_char(char c)
{
switch (c) {
case '\a': return 'a';
case '\b': return 'b';
case '\f': return 'f';
case '\n': return 'n';
case '\r': return 'r';
case '\t': return 't';
case '\v': return 'v';
case '"':
case '\\':
return c;

View File

@ -40,8 +40,12 @@ static void test_escape_string(void)
g_assert_cmpstr(buf, ==, "\"quoted \\\"\\\\\\\" backslash\"");
wmem_free(NULL, buf);
buf = ws_escape_string(NULL, "bytes \xfe\xff", TRUE);
g_assert_cmpstr(buf, ==, "\"bytes \\xfe\\xff\"");
buf = ws_escape_string(NULL, "whitespace \t \n \r \f \v", TRUE);
g_assert_cmpstr(buf, ==, "\"whitespace \\t \\n \\r \\f \\v""\"");
wmem_free(NULL, buf);
buf = ws_escape_string(NULL, "bytes \xfe\xff", FALSE);
g_assert_cmpstr(buf, ==, "bytes \\xfe\\xff");
wmem_free(NULL, buf);
}