Fix to handle '\v' (vertical tab) by g_strescape() and g_strcompress().

fix enables g_strescape() and g_strcompress() to handle '\v' along with other
special characters - '\b', '\f', '\n', '\r', '\t', '\'.

https://bugzilla.gnome.org/show_bug.cgi?id=664830

Signed-off-by: Ravi Sankar Guntur <ravi.g@samsung.com>
This commit is contained in:
Ravi Sankar Guntur 2011-12-20 14:49:53 +05:30 committed by Matthias Clasen
parent 030bf82340
commit 8ca2647c74
2 changed files with 16 additions and 9 deletions

View File

@ -2022,6 +2022,9 @@ g_strcompress (const gchar *source)
case 't':
*q++ = '\t';
break;
case 'v':
*q++ = '\v';
break;
default: /* Also handles \" and \\ */
*q++ = *p;
break;
@ -2042,7 +2045,7 @@ out:
* @source: a string to escape
* @exceptions: a string of characters not to escape in @source
*
* Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\'
* Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\v', '\'
* and '&quot;' in the string @source by inserting a '\' before
* them. Additionally all characters in the range 0x01-0x1F (everything
* below SPACE) and in the range 0x7F-0xFF (all non-ASCII chars) are
@ -2109,6 +2112,10 @@ g_strescape (const gchar *source,
*q++ = '\\';
*q++ = 't';
break;
case '\v':
*q++ = '\\';
*q++ = 'v';
break;
case '\\':
*q++ = '\\';
*q++ = '\\';

View File

@ -374,9 +374,9 @@ test_strcompress_strescape (void)
g_test_trap_assert_failed ();
}
str = g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313\\12345z");
str = g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313\\12345z");
g_assert (str != NULL);
g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\003\177\234\313\12345z");
g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313\12345z");
g_free (str);
/* test escape */
@ -389,22 +389,22 @@ test_strcompress_strescape (void)
g_test_trap_assert_failed ();
}
str = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313", NULL);
str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
g_assert (str != NULL);
g_assert_cmpstr (str, ==, "abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313");
g_assert_cmpstr (str, ==, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313");
g_free (str);
str = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313",
str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313",
"\b\f\001\002\003\004");
g_assert (str != NULL);
g_assert_cmpstr (str, ==, "abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313");
g_assert_cmpstr (str, ==, "abc\\\\\\\"\b\f\\n\\r\\t\\v\003\\177\\234\\313");
g_free (str);
/* round trip */
tmp = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313", NULL);
tmp = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
str = g_strcompress (tmp);
g_assert (str != NULL);
g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\003\177\234\313");
g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313");
g_free (str);
g_free (tmp);
}