Lines Matching refs:L
92 static int utflen (lua_State *L) { in utflen() argument
95 const char *s = luaL_checklstring(L, 1, &len); in utflen()
96 lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); in utflen()
97 lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len); in utflen()
98 int lax = lua_toboolean(L, 4); in utflen()
99 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2, in utflen()
101 luaL_argcheck(L, --posj < (lua_Integer)len, 3, in utflen()
106 luaL_pushfail(L); /* return fail ... */ in utflen()
107 lua_pushinteger(L, posi + 1); /* ... and current position */ in utflen()
113 lua_pushinteger(L, n); in utflen()
122 static int codepoint (lua_State *L) { in codepoint() argument
124 const char *s = luaL_checklstring(L, 1, &len); in codepoint()
125 lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); in codepoint()
126 lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len); in codepoint()
127 int lax = lua_toboolean(L, 4); in codepoint()
130 luaL_argcheck(L, posi >= 1, 2, "out of bounds"); in codepoint()
131 luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of bounds"); in codepoint()
134 return luaL_error(L, "string slice too long"); in codepoint()
136 luaL_checkstack(L, n, "string slice too long"); in codepoint()
143 return luaL_error(L, "invalid UTF-8 code"); in codepoint()
144 lua_pushinteger(L, code); in codepoint()
151 static void pushutfchar (lua_State *L, int arg) { in pushutfchar() argument
152 lua_Unsigned code = (lua_Unsigned)luaL_checkinteger(L, arg); in pushutfchar()
153 luaL_argcheck(L, code <= MAXUTF, arg, "value out of range"); in pushutfchar()
154 lua_pushfstring(L, "%U", (long)code); in pushutfchar()
161 static int utfchar (lua_State *L) { in utfchar() argument
162 int n = lua_gettop(L); /* number of arguments */ in utfchar()
164 pushutfchar(L, 1); in utfchar()
168 luaL_buffinit(L, &b); in utfchar()
170 pushutfchar(L, i); in utfchar()
183 static int byteoffset (lua_State *L) { in byteoffset() argument
185 const char *s = luaL_checklstring(L, 1, &len); in byteoffset()
186 lua_Integer n = luaL_checkinteger(L, 2); in byteoffset()
188 posi = u_posrelat(luaL_optinteger(L, 3, posi), len); in byteoffset()
189 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, in byteoffset()
197 return luaL_error(L, "initial position is a continuation byte"); in byteoffset()
217 lua_pushinteger(L, posi + 1); in byteoffset()
219 luaL_pushfail(L); in byteoffset()
224 static int iter_aux (lua_State *L, int strict) { in iter_aux() argument
226 const char *s = luaL_checklstring(L, 1, &len); in iter_aux()
227 lua_Integer n = lua_tointeger(L, 2) - 1; in iter_aux()
240 return luaL_error(L, "invalid UTF-8 code"); in iter_aux()
241 lua_pushinteger(L, n + 1); in iter_aux()
242 lua_pushinteger(L, code); in iter_aux()
248 static int iter_auxstrict (lua_State *L) { in iter_auxstrict() argument
249 return iter_aux(L, 1); in iter_auxstrict()
252 static int iter_auxlax (lua_State *L) { in iter_auxlax() argument
253 return iter_aux(L, 0); in iter_auxlax()
257 static int iter_codes (lua_State *L) { in iter_codes() argument
258 int lax = lua_toboolean(L, 2); in iter_codes()
259 luaL_checkstring(L, 1); in iter_codes()
260 lua_pushcfunction(L, lax ? iter_auxlax : iter_auxstrict); in iter_codes()
261 lua_pushvalue(L, 1); in iter_codes()
262 lua_pushinteger(L, 0); in iter_codes()
283 LUAMOD_API int luaopen_utf8 (lua_State *L) { in luaopen_utf8() argument
284 luaL_newlib(L, funcs); in luaopen_utf8()
285 lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1); in luaopen_utf8()
286 lua_setfield(L, -2, "charpattern"); in luaopen_utf8()