24#define MAXUNICODE 0x10FFFFu
26#define MAXUTF 0x7FFFFFFFu
31#if (UINT_MAX >> 30) >= 1
32typedef 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) {
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));
268#define UTF8PATT "[\0-\x7F\xC2-\xFD][\x80-\xBF]*"
278 {
"charpattern",
NULL},
CURL_EXTERN int void * arg
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API void lua_pushlstring(lua_State *L, const char *s, size_t len)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API int lua_gettop(lua_State *L)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *mes)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
#define luaL_checkstring(L, n)
#define luaL_argcheck(L, cond, numarg, extramsg)
#define lua_pushcfunction(L, f)
#define luaL_newlib(L, l)
#define lua_tointeger(L, i)
LUA_UNSIGNED lua_Unsigned
static void pushutfchar(lua_State *L, int arg)
static int utfchar(lua_State *L)
static int iter_auxlax(lua_State *L)
static int byteoffset(lua_State *L)
static int utflen(lua_State *L)
static const luaL_Reg funcs[]
static int iter_codes(lua_State *L)
static const char * utf8_decode(const char *s, utfint *val, int strict)
static lua_Integer u_posrelat(lua_Integer pos, size_t len)
static int iter_aux(lua_State *L, int strict)
LUAMOD_API int luaopen_utf8(lua_State *L)
static int codepoint(lua_State *L)
static int iter_auxstrict(lua_State *L)
CURL_EXTERN CURLMcode curl_socket_t s