aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-23 13:45:44 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-23 13:45:44 +0000
commit77570ec7f9d6865c29c55b1535c00fb7c1d5b4b3 (patch)
treea043e59b8ae11badd054baab3859a423d70ee9d9 /src/libutil/util.c
parent6afff053762ad4fb377ec651da8a3cec04076313 (diff)
downloadrspamd-77570ec7f9d6865c29c55b1535c00fb7c1d5b4b3.tar.gz
rspamd-77570ec7f9d6865c29c55b1535c00fb7c1d5b4b3.zip
Add lowercase utility for utf8 strings.
Diffstat (limited to 'src/libutil/util.c')
-rw-r--r--src/libutil/util.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index dbc34733e..5a42e4f8e 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -663,6 +663,37 @@ rspamd_str_lc (gchar *str, guint size)
}
}
+/*
+ * The purpose of this function is fast and in place conversion of a unicode
+ * string to lower case, so some locale peculiarities are simply ignored
+ * If the target string is longer than initial one, then we just trim it
+ */
+void
+rspamd_str_lc_utf8 (gchar *str, guint size)
+{
+ const gchar *s = str, *p;
+ gchar *d = str;
+ guint remain = size;
+ gint r;
+ gunichar uc;
+
+ while (remain > 0) {
+ uc = g_utf8_get_char_validated (s, remain);
+ uc = g_unichar_tolower (uc);
+ p = g_utf8_next_char (s);
+
+ if (p - s == 0) {
+ return;
+ }
+
+ r = g_unichar_to_utf8 (uc, d);
+ g_assert (r > 0);
+ remain -= r;
+ s = p;
+ d += r;
+ }
+}
+
#ifndef HAVE_SETPROCTITLE
static gchar *title_buffer = 0;