egg: In egg_assert_cmpmem() output printable without encoding
authorStef Walter <stefw@collabora.co.uk>
Thu, 17 Nov 2011 08:20:50 +0000 (09:20 +0100)
committerStef Walter <stefw@collabora.co.uk>
Wed, 23 Nov 2011 08:10:50 +0000 (09:10 +0100)
egg/egg-testing.c

index 9f30ec6..85d4b0b 100644 (file)
@@ -59,6 +59,7 @@ egg_test_escape_data (const guchar *data,
                       gsize n_data)
 {
        GString *result;
+       gchar c;
        gsize i;
        guchar j;
 
@@ -66,12 +67,16 @@ egg_test_escape_data (const guchar *data,
 
        result = g_string_sized_new (n_data * 2 + 1);
        for (i = 0; i < n_data; ++i) {
-               g_string_append (result, "\\x");
-
-               j = data[i] >> 4 & 0xf;
-               g_string_append_c (result, HEXC[j]);
-               j = data[i] & 0xf;
-               g_string_append_c (result, HEXC[j]);
+               c = data[i];
+               if (g_ascii_isprint (c)) {
+                       g_string_append_c (result, c);
+               } else {
+                       g_string_append (result, "\\x");
+                       j = c >> 4 & 0xf;
+                       g_string_append_c (result, HEXC[j]);
+                       j = c & 0xf;
+                       g_string_append_c (result, HEXC[j]);
+               }
        }
 
        return g_string_free (result, FALSE);