[gcr] egg: In egg_assert_cmpmem() output printable without encoding



commit 56132c69b650504d05f485f3222263a170fb5cc1
Author: Stef Walter <stefw collabora co uk>
Date:   Thu Nov 17 09:20:50 2011 +0100

    egg: In egg_assert_cmpmem() output printable without encoding

 egg/egg-testing.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/egg/egg-testing.c b/egg/egg-testing.c
index 9f30ec6..85d4b0b 100644
--- a/egg/egg-testing.c
+++ b/egg/egg-testing.c
@@ -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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]