[evolution-data-server] Added e_util_utf8_normalize()



commit b963d3e26ffc32dfa0238ba930519dbe0330e17a
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Mon Nov 19 20:19:43 2012 +0900

    Added e_util_utf8_normalize()
    
    A utility function to lowercase/remove accents from a utf8 string

 libedataserver/e-data-server-util.c |   34 ++++++++++++++++++++++++++++++++++
 libedataserver/e-data-server-util.h |    1 +
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index 70fad17..ab252b5 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -526,6 +526,40 @@ e_util_utf8_data_make_valid (const gchar *data,
 }
 
 /**
+ * e_util_utf8_normalize:
+ * @str: a UTF-8 string
+ *
+ * Normalizes @str by making it all lower case and removing any accents from it.
+ *
+ * Returns: The normalized version of @str, or %NULL if @str was not valid UTF-8
+ *
+ * Since: 3.8
+ */
+gchar *
+e_util_utf8_normalize (const gchar *str)
+{
+	gchar *valid = NULL;
+	gchar *normal, *casefolded = NULL;
+
+	if (str == NULL)
+		return NULL;
+
+	if (!g_utf8_validate (str, -1, NULL)) {
+		valid = e_util_utf8_make_valid (str);
+		str = valid;
+	}
+
+	normal = e_util_utf8_remove_accents (str);
+	if (normal)
+		casefolded = g_utf8_casefold (normal, -1);
+
+	g_free (valid);
+	g_free (normal);
+
+	return casefolded;
+}
+
+/**
  * e_util_ensure_gdbus_string:
  * @str: a possibly invalid UTF-8 string, or %NULL
  * @gdbus_str: return location for the corrected string
diff --git a/libedataserver/e-data-server-util.h b/libedataserver/e-data-server-util.h
index 911c77d..2687e6e 100644
--- a/libedataserver/e-data-server-util.h
+++ b/libedataserver/e-data-server-util.h
@@ -52,6 +52,7 @@ gchar *		e_util_utf8_remove_accents	(const gchar *str);
 gchar *		e_util_utf8_make_valid		(const gchar *str);
 gchar *		e_util_utf8_data_make_valid	(const gchar *data,
 						 gsize data_bytes);
+gchar *         e_util_utf8_normalize           (const gchar *str);
 const gchar *   e_util_ensure_gdbus_string	(const gchar *str,
 						 gchar **gdbus_str);
 guint64		e_util_gthread_id		(GThread *thread);



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