summary refs log tree commit diff stats
path: root/src/common/text.c
diff options
context:
space:
mode:
authorJoseph Bisch <joseph.bisch@gmail.com>2017-10-02 15:11:42 -0400
committerTingPing <tingping@tingping.se>2017-10-02 15:11:42 -0400
commit07f1fc60dac480d3e4ca8e98ec1c0e08c050676d (patch)
tree073655aad78fe81d35fefb956b567a29ac2dbbda /src/common/text.c
parent0c494a9c24c431f39b24abb5d90b6221d554a688 (diff)
Use g_utf8_make_valid if available for cleaner utf8 handling (#2065)
Diffstat (limited to 'src/common/text.c')
-rw-r--r--src/common/text.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/common/text.c b/src/common/text.c
index 2677ebc4..4a274f98 100644
--- a/src/common/text.c
+++ b/src/common/text.c
@@ -814,6 +814,16 @@ text_convert_invalid (const gchar* text, gssize len, GIConv converter, const gch
 gchar *
 text_fixup_invalid_utf8 (const gchar* text, gssize len, gsize *len_out)
 {
+#if GLIB_CHECK_VERSION (2, 52, 0)
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+	gchar *result = g_utf8_make_valid (text, len);
+G_GNUC_END_IGNORE_DEPRECATIONS
+	if (len_out)
+	{
+		*len_out = strlen (result);
+	}
+	return result;
+#else
 	static GIConv utf8_fixup_converter = NULL;
 	if (utf8_fixup_converter == NULL)
 	{
@@ -821,6 +831,7 @@ text_fixup_invalid_utf8 (const gchar* text, gssize len, gsize *len_out)
 	}
 
 	return text_convert_invalid (text, len, utf8_fixup_converter, unicode_fallback_string, len_out);
+#endif
 }
 
 void