[evolution-data-server/openismus-work-master: 2/8] Added e_util_utf8_normalize()



commit c5b4c2004479e9078081140819e8c6aa5db9dce5
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 |   42 +++++++++++++++++++++++++++++++++++
 libedataserver/e-data-server-util.h |    1 +
 2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index 8320ecf..ba8f0d5 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -526,6 +526,48 @@ 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)
+{
+	GString *res;
+	gunichar unich;
+	gchar *p, *tmp;
+
+	if (str == NULL)
+		return NULL;
+
+	tmp = e_util_utf8_remove_accents (str);
+	if (!tmp)
+		return NULL;
+
+	res = g_string_new ("");
+
+	for (p = e_util_unicode_get_utf8 (tmp, &unich); p && unich; p = e_util_unicode_get_utf8 (p, &unich)) {
+		g_string_append_unichar (res, g_unichar_tolower (unich));
+	}
+
+	g_free (tmp);
+
+	/* it was invalid unichar string */
+	if (p == NULL) {
+		g_string_free (res, TRUE);
+		return NULL;
+	}
+
+	return g_string_free (res, FALSE);
+}
+
+
+/**
  * 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]