summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/lua_util.c')
-rw-r--r--src/lua/lua_util.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 881257ed3..af4673af8 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -2513,15 +2513,18 @@ lua_util_is_utf_mixed_script(lua_State *L)
{
LUA_TRACE_POINT;
gsize len_of_string;
- const gchar *end, *string_to_check = lua_tolstring (L, 1, &len_of_string);
+ const gchar *string_to_check = lua_tolstring (L, 1, &len_of_string);
UScriptCode last_script_code = USCRIPT_INVALID_CODE;
UErrorCode uc_err = U_ZERO_ERROR;
- if (string_to_check && g_utf8_validate (string_to_check, len_of_string, &end)) {
- len_of_string = g_utf8_strlen (string_to_check, len_of_string);
-
- for(; *string_to_check; string_to_check = g_utf8_next_char(string_to_check)){
- gunichar char_to_check = g_utf8_get_char(string_to_check);
+ if (string_to_check) {
+ uint index = 0;
+ UChar32 char_to_check = 0;
+ while(index < len_of_string) {
+ U8_NEXT(string_to_check, index, len_of_string, char_to_check);
+ if (char_to_check < 0 ) {
+ return luaL_error (L, "passed string is not valid utf");
+ }
UScriptCode current_script_code = uscript_getScript(char_to_check, &uc_err);
if (uc_err != U_ZERO_ERROR){
msg_err ("cannot get unicode script for character, error: %s", u_errorName (uc_err));