forked from osmocom/wireshark
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:
parent
54bdc20e45
commit
9c61142195
|
@ -271,6 +271,13 @@ static inline char
|
||||||
escape_char(char c)
|
escape_char(char c)
|
||||||
{
|
{
|
||||||
switch (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 '"':
|
||||||
case '\\':
|
case '\\':
|
||||||
return c;
|
return c;
|
||||||
|
|
|
@ -40,8 +40,12 @@ static void test_escape_string(void)
|
||||||
g_assert_cmpstr(buf, ==, "\"quoted \\\"\\\\\\\" backslash\"");
|
g_assert_cmpstr(buf, ==, "\"quoted \\\"\\\\\\\" backslash\"");
|
||||||
wmem_free(NULL, buf);
|
wmem_free(NULL, buf);
|
||||||
|
|
||||||
buf = ws_escape_string(NULL, "bytes \xfe\xff", TRUE);
|
buf = ws_escape_string(NULL, "whitespace \t \n \r \f \v", TRUE);
|
||||||
g_assert_cmpstr(buf, ==, "\"bytes \\xfe\\xff\"");
|
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);
|
wmem_free(NULL, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue