[balsa/wip/gtk4: 314/351] utf8-sanitize: Use g_utf8_make_valid



commit b4cc027770ffe83bf323c79727c437ba989406d5
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Apr 30 11:38:55 2018 -0400

    utf8-sanitize: Use g_utf8_make_valid
    
    when the string is not UTF-8, and conversion either fails or was not
    requested. We used to just stuff '?' characters into the string in place
    of invalid non-ASCII bytes. Make-valid uses the 'U+FFFD REPLACEMENT
    CHARACTER' instead, and does it more carefully.

 libbalsa/misc.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index b3252b5..4f6063c 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -304,9 +304,9 @@ libbalsa_utf8_sanitize(gchar **text, gboolean fallback,
 {
     gchar *p;
 
-    if (target)
+    if (target != NULL)
        *target = NULL;
-    if (!*text || g_utf8_validate(*text, -1, NULL))
+    if (*text == NULL || g_utf8_validate(*text, -1, NULL))
        return TRUE;
 
     if (fallback) {
@@ -317,10 +317,10 @@ libbalsa_utf8_sanitize(gchar **text, gboolean fallback,
        p = g_convert(*text, strlen(*text), "utf-8", use_enc, NULL,
                       &b_written, &conv_error);
 
-       if (p) {
+       if (p != NULL) {
            g_free(*text);
            *text = p;
-           if (target)
+           if (target != NULL)
                *target = use_enc;
            return FALSE;
        }
@@ -328,9 +328,10 @@ libbalsa_utf8_sanitize(gchar **text, gboolean fallback,
                   conv_error->message);
        g_error_free(conv_error);
     }
-    p = *text;
-    while (!g_utf8_validate(p, -1, (const gchar **) &p))
-       *p++ = '?';
+
+    p = g_utf8_make_valid(*text, -1);
+    g_free(*text);
+    *text = p;
 
     return FALSE;
 }


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