changeset 341:fe061ead51cc

Perform character set conversion after item formatting step instead of before it. This should remedy the potential issue of formatting not taking UTF8 multibyte into account, as our formatting unfortunately does not support multibyte encoding. This way the data should stay in ISO-8859-1 format just up to outputting it.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 13 Jan 2020 16:29:47 +0200
parents 6f8c431a3040
children 0de1012e5dde
files sidinfo.c
diffstat 1 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/sidinfo.c	Mon Jan 13 16:24:57 2020 +0200
+++ b/sidinfo.c	Mon Jan 13 16:29:47 2020 +0200
@@ -768,22 +768,25 @@
     const char *d_str, const int d_int,
     const BOOL convert)
 {
-    char *str, *tmp;
+    char *formatted, *escaped;
 
-    if (d_str != NULL && setChConv.enabled && convert)
+    escaped = sidutil_escape_string(d_str, optEscapeChars);
+
+    if ((formatted = siItemFormatStrPrint(fmt, otype, escaped, d_int)) != NULL)
     {
-        char *tmp2 = sidutil_chconv_convert(&setChConv, d_str);
-        tmp = sidutil_escape_string(tmp2, optEscapeChars);
-        th_free(tmp2);
+        char *converted;
+        if (setChConv.enabled && convert &&
+            (converted = sidutil_chconv_convert(&setChConv, formatted)) != NULL)
+        {
+            fputs(converted, outfh);
+            th_free(converted);
+        }
+        else
+            fputs(formatted, outfh);
     }
-    else
-        tmp = sidutil_escape_string(d_str, optEscapeChars);
 
-    if ((str = siItemFormatStrPrint(fmt, otype, tmp, d_int)) != NULL)
-        fputs(str, outfh);
-
-    th_free(str);
-    th_free(tmp);
+    th_free(formatted);
+    th_free(escaped);
 
     *shown = TRUE;
 }