gsize n_data)
{
GString *result;
+ gchar c;
gsize i;
guchar j;
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);