diff options
| -rw-r--r-- | lutf8lib.c | 12 |
1 files changed, 6 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: lutf8lib.c,v 1.2 2014/02/06 20:03:24 roberto Exp roberto $ |
| 3 | ** Standard library for UTF-8 manipulation | 3 | ** Standard library for UTF-8 manipulation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -24,7 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | /* from strlib */ | 25 | /* from strlib */ |
| 26 | /* translate a relative string position: negative means back from end */ | 26 | /* translate a relative string position: negative means back from end */ |
| 27 | static lua_Integer posrelat (lua_Integer pos, size_t len) { | 27 | static lua_Integer u_posrelat (lua_Integer pos, size_t len) { |
| 28 | if (pos >= 0) return pos; | 28 | if (pos >= 0) return pos; |
| 29 | else if (0u - (size_t)pos > len) return 0; | 29 | else if (0u - (size_t)pos > len) return 0; |
| 30 | else return (lua_Integer)len + pos + 1; | 30 | else return (lua_Integer)len + pos + 1; |
| @@ -69,7 +69,7 @@ static int utflen (lua_State *L) { | |||
| 69 | const char *ends; | 69 | const char *ends; |
| 70 | size_t len; | 70 | size_t len; |
| 71 | const char *s = luaL_checklstring(L, 1, &len); | 71 | const char *s = luaL_checklstring(L, 1, &len); |
| 72 | lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), 1); | 72 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), 1); |
| 73 | luaL_argcheck(L, 1 <= posi && posi <= (lua_Integer)len, 1, | 73 | luaL_argcheck(L, 1 <= posi && posi <= (lua_Integer)len, 1, |
| 74 | "initial position out of string"); | 74 | "initial position out of string"); |
| 75 | ends = s + len; | 75 | ends = s + len; |
| @@ -91,8 +91,8 @@ static int utflen (lua_State *L) { | |||
| 91 | static int codepoint (lua_State *L) { | 91 | static int codepoint (lua_State *L) { |
| 92 | size_t len; | 92 | size_t len; |
| 93 | const char *s = luaL_checklstring(L, 1, &len); | 93 | const char *s = luaL_checklstring(L, 1, &len); |
| 94 | lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), len); | 94 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); |
| 95 | lua_Integer pose = posrelat(luaL_optinteger(L, 3, posi), len); | 95 | lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len); |
| 96 | int n; | 96 | int n; |
| 97 | const char *se; | 97 | const char *se; |
| 98 | luaL_argcheck(L, posi >= 1, 2, "out of range"); | 98 | luaL_argcheck(L, posi >= 1, 2, "out of range"); |
| @@ -152,7 +152,7 @@ static int byteoffset (lua_State *L) { | |||
| 152 | size_t len; | 152 | size_t len; |
| 153 | const char *s = luaL_checklstring(L, 1, &len); | 153 | const char *s = luaL_checklstring(L, 1, &len); |
| 154 | int n = luaL_checkint(L, 2); | 154 | int n = luaL_checkint(L, 2); |
| 155 | lua_Integer posi = posrelat(luaL_optinteger(L, 3, 1), len) - 1; | 155 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 3, 1), len) - 1; |
| 156 | luaL_argcheck(L, 0 <= posi && posi <= (lua_Integer)len, 3, | 156 | luaL_argcheck(L, 0 <= posi && posi <= (lua_Integer)len, 3, |
| 157 | "position out of range"); | 157 | "position out of range"); |
| 158 | if (n == 0) { | 158 | if (n == 0) { |
