Changeset View
Changeset View
Standalone View
Standalone View
contrib/lua/src/lutf8lib.c
/* | /* | ||||
** $Id: lutf8lib.c,v 1.16 2016/12/22 13:08:50 roberto Exp $ | ** $Id: lutf8lib.c,v 1.16.1.1 2017/04/19 17:29:57 roberto Exp $ | ||||
** Standard library for UTF-8 manipulation | ** Standard library for UTF-8 manipulation | ||||
** See Copyright Notice in lua.h | ** See Copyright Notice in lua.h | ||||
*/ | */ | ||||
#define lutf8lib_c | #define lutf8lib_c | ||||
#define LUA_LIB | #define LUA_LIB | ||||
#include "lprefix.h" | #include "lprefix.h" | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | static int byteoffset (lua_State *L) { | ||||
luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, | ||||
"position out of range"); | "position out of range"); | ||||
if (n == 0) { | if (n == 0) { | ||||
/* find beginning of current byte sequence */ | /* find beginning of current byte sequence */ | ||||
while (posi > 0 && iscont(s + posi)) posi--; | while (posi > 0 && iscont(s + posi)) posi--; | ||||
} | } | ||||
else { | else { | ||||
if (iscont(s + posi)) | if (iscont(s + posi)) | ||||
luaL_error(L, "initial position is a continuation byte"); | return luaL_error(L, "initial position is a continuation byte"); | ||||
if (n < 0) { | if (n < 0) { | ||||
while (n < 0 && posi > 0) { /* move back */ | while (n < 0 && posi > 0) { /* move back */ | ||||
do { /* find beginning of previous character */ | do { /* find beginning of previous character */ | ||||
posi--; | posi--; | ||||
} while (posi > 0 && iscont(s + posi)); | } while (posi > 0 && iscont(s + posi)); | ||||
n++; | n++; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |