24 #define MAXUNICODE 0x10FFFFu 26 #define MAXUTF 0x7FFFFFFFu 31 #if (UINT_MAX >> 30) >= 1 32 typedef unsigned int utfint;
38 #define iscont(p) ((*(p) & 0xC0) == 0x80) 44 if (pos >= 0)
return pos;
45 else if (0u - (
size_t)pos > len)
return 0;
58 static const utfint limits[] =
59 {~(
utfint)0, 0x80, 0x800, 0x10000u, 0x200000u, 0x4000000u};
60 unsigned int c = (
unsigned char)s[0];
66 for (; c & 0x40; c <<= 1) {
67 unsigned int cc = (
unsigned char)s[++count];
68 if ((cc & 0xC0) != 0x80)
70 res = (res << 6) | (cc & 0x3F);
72 res |= ((
utfint)(c & 0x7F) << (count * 5));
73 if (count > 5 || res >
MAXUTF || res < limits[count])
79 if (res >
MAXUNICODE || (0xD800u <= res && res <= 0xDFFFu))
100 "initial position out of bounds");
102 "final position out of bounds");
103 while (posi <= posj) {
104 const char *s1 =
utf8_decode(s + posi, NULL, !lax);
132 if (posi > pose)
return 0;
133 if (pose - posi >= INT_MAX)
134 return luaL_error(L,
"string slice too long");
135 n = (int)(pose - posi) + 1;
139 for (s += posi - 1; s < se;) {
169 for (i = 1; i <= n; i++) {
190 "position out of bounds");
193 while (posi > 0 &&
iscont(s + posi)) posi--;
197 return luaL_error(L,
"initial position is a continuation byte");
199 while (n < 0 && posi > 0) {
202 }
while (posi > 0 &&
iscont(s + posi));
211 }
while (
iscont(s + posi));
232 while (
iscont(s + n)) n++;
268 #define UTF8PATT "[\0-\x7F\xC2-\xFD][\x80-\xBF]*" 278 {
"charpattern", NULL},
LUAMOD_API int luaopen_utf8(lua_State *L)
static int byteoffset(lua_State *L)
static int iter_auxlax(lua_State *L)
#define lua_pushcfunction(L, f)
static lua_Integer u_posrelat(lua_Integer pos, size_t len)
static int iter_auxstrict(lua_State *L)
static const luaL_Reg funcs[]
LUA_API int lua_toboolean(lua_State *L, int idx)
static int utfchar(lua_State *L)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
#define lua_tointeger(L, i)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
LUA_API void lua_pushvalue(lua_State *L, int idx)
static void pushutfchar(lua_State *L, int arg)
LUALIB_API const char * luaL_checklstring(lua_State *L, int arg, size_t *len)
static const char * utf8_decode(const char *s, utfint *val, int strict)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
static int iter_codes(lua_State *L)
static int utflen(lua_State *L)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
static int codepoint(lua_State *L)
static int iter_aux(lua_State *L, int strict)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int arg, lua_Integer def)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
#define luaL_newlib(L, l)
LUA_UNSIGNED lua_Unsigned
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
#define luaL_argcheck(L, cond, arg, extramsg)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
LUA_API int lua_gettop(lua_State *L)
#define luaL_checkstring(L, n)