From 6f16b22c4a6a878ca0f07e57da50f7ac04fef306 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 20 Jan 2013 13:21:57 -0800 Subject: 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 Reviewed-by: Peter Hutterer --- xprop.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/xprop.c b/xprop.c index 9773ac3..4d2e3c2 100644 --- a/xprop.c +++ b/xprop.c @@ -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 = ""; 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': -- cgit v1.2.3