aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-09-12 19:13:55 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-09-12 19:13:55 +0100
commitb9c7fd94324f54ac66aa3cf6dc4c89a626c72fe5 (patch)
treee7c28fae463573e11c65f75c01cc37cc67f596f4 /src/lua
parent7d128832b71712049d024f34f0a70f59ba2fa18c (diff)
downloadrspamd-b9c7fd94324f54ac66aa3cf6dc4c89a626c72fe5.tar.gz
rspamd-b9c7fd94324f54ac66aa3cf6dc4c89a626c72fe5.zip
[Minor] Use libicu to find uppercase letters
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_util.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index cfa44eaf3..a9f01429e 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -1172,33 +1172,28 @@ lua_util_fold_header (lua_State *L)
static gint
lua_util_is_uppercase (lua_State *L)
{
- const gchar *str, *p;
- gsize sz, remain;
- gunichar uc;
+ const gchar *str;
+ gsize sz;
+ gint32 i = 0;
+ UChar32 uc;
guint nlc = 0, nuc = 0;
str = luaL_checklstring (L, 1, &sz);
- remain = sz;
- if (str && remain > 0) {
- while (remain > 0) {
- uc = g_utf8_get_char_validated (str, remain);
- p = g_utf8_next_char (str);
+ if (str && sz > 0) {
+ while (i >= 0 && i < sz) {
+ U8_NEXT (str, i, sz, uc);
- if (p - str > (gint) remain) {
+ if (uc < 0) {
break;
}
- remain -= p - str;
-
- if (g_unichar_isupper (uc)) {
+ if (u_isupper (uc)) {
nuc++;
}
- else if (g_unichar_islower (uc)) {
+ else if (u_islower (uc)) {
nlc++;
}
-
- str = p;
}
}