[evolution-data-server/openismus-work: 41/122] Added e_util_utf8_normalize()



commit c588b82d8cc8fa991203890b34803167e505b467
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 cf330fa..bfd497e 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]