diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-01-20 13:21:57 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-01-22 22:28:56 -0800 |
commit | 6f16b22c4a6a878ca0f07e57da50f7ac04fef306 (patch) | |
tree | 112669a32e44480b00f4051dc95f08a0b0abe5a4 /xprop.c | |
parent | 0384b1c6567d3f90975665ed4e7b3a09947cabee (diff) |
Add unicode argument to Format_Len_String to reduce code duplication
Allows us to get rid of a second copy of the code that differed only
in the unicode argument passed on to Format_String.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'xprop.c')
-rw-r--r-- | xprop.c | 25 |
1 files changed, 6 insertions, 19 deletions
@@ -724,7 +724,7 @@ Format_String (const char *string, int unicode) } static const char * -Format_Len_String (const char *string, int len) +Format_Len_String (const char *string, int len, int unicode) { char *data; const char *result; @@ -736,7 +736,7 @@ Format_Len_String (const char *string, int len) memcpy(data, string, len); data[len] = '\0'; - result = Format_String(data, 0); + result = Format_String(data, unicode); free(data); return result; @@ -901,7 +901,7 @@ Format_Len_Text (const char *string, int len, Atom encoding) *_buf_ptr++ = '\0'; return _formatting_buffer; } else - return Format_Len_String(string, len); + return Format_Len_String(string, len, 0); } /* @@ -1002,7 +1002,7 @@ Format_Len_Unicode (const char *string, int len) error = "<Invalid UTF-8 string: Unknown error>"; break; } - result = Format_Len_String(string, len); + result = Format_Len_String(string, len, 0); /* result is stored in _formatting_buffer, so make a temporary copy before we overwrite _formatting_buffer with error */ data = strdup(result); @@ -1016,20 +1016,7 @@ Format_Len_Unicode (const char *string, int len) return _formatting_buffer; } - if (!is_utf8_locale()) - return Format_Len_String(string, len); - - data = malloc(len+1); - if (!data) - Fatal_Error("Out of memory!"); - - memcpy(data, string, len); - data[len] = '\0'; - - result = Format_String(data, 1); - free(data); - - return result; + return Format_Len_String(string, len, is_utf8_locale()); } /* @@ -1083,7 +1070,7 @@ Format_Thunk (thunk t, char format_char) switch (format_char) { case 's': - return Format_Len_String(t.extra_value, (int)t.value); + return Format_Len_String(t.extra_value, (int)t.value, 0); case 'u': return Format_Len_Unicode(t.extra_value, (int)t.value); case 't': |