aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-unicode.c
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2010-01-08 23:29:42 +0800
committerMilan Crha <mcrha@redhat.com>2010-01-08 23:29:42 +0800
commitabaecf816e8b9f2c0afc754223c75e8634702b4c (patch)
treec88e4e571259683cfe0c2bee7d30f8676f138b02 /e-util/e-unicode.c
parent79741ccd3f90c4c8aab672b508606d63c3899584 (diff)
downloadgsoc2013-evolution-abaecf816e8b9f2c0afc754223c75e8634702b4c.tar.gz
gsoc2013-evolution-abaecf816e8b9f2c0afc754223c75e8634702b4c.tar.zst
gsoc2013-evolution-abaecf816e8b9f2c0afc754223c75e8634702b4c.zip
Bug #606340 - Crash on non-utf8 letter in mail folder name
Diffstat (limited to 'e-util/e-unicode.c')
-rw-r--r--e-util/e-unicode.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/e-util/e-unicode.c b/e-util/e-unicode.c
index 88f6d0605a..2e8969f718 100644
--- a/e-util/e-unicode.c
+++ b/e-util/e-unicode.c
@@ -211,6 +211,32 @@ e_utf8_from_locale_string_sized (const gchar *string, gint bytes)
}
/**
+ * e_utf8_ensure_valid:
+ * @string String to make valid UTF-8.
+ *
+ * Ensures the returned string will be valid UTF-8 string, thus gtk functions expecting
+ * only valid UTF-8 texts will not crash.
+ *
+ * Returned pointer should be freed with g_free.
+ **/
+gchar *
+e_utf8_ensure_valid (const gchar *string)
+{
+ gchar *res = g_strdup (string), *p;
+
+ if (!res)
+ return res;
+
+ p = res;
+ while (!g_utf8_validate (p, -1, (const gchar **) &p)) {
+ /* make all invalid characters appear as question marks */
+ *p = '?';
+ }
+
+ return res;
+}
+
+/**
* e_unichar_to_utf8:
* @c: a ISO10646 character code
* @outbuf: output buffer, must have at least 6 bytes of space.