MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / utflen

Function utflen

third-party/lua-5.5.0/src/lutf8lib.c:87–110  ·  view source on GitHub ↗

** utf8len(s [, i [, j [, lax]]]) --> number of characters that ** start in the range [i,j], or nil + current position if 's' is not ** well formed in that interval */

Source from the content-addressed store, hash-verified

85** well formed in that interval
86*/
87static int utflen (lua_State *L) {
88 lua_Integer n = 0; /* counter for the number of characters */
89 size_t len; /* string length in bytes */
90 const char *s = luaL_checklstring(L, 1, &len);
91 lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);
92 lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);
93 int lax = lua_toboolean(L, 4);
94 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,
95 "initial position out of bounds");
96 luaL_argcheck(L, --posj < (lua_Integer)len, 3,
97 "final position out of bounds");
98 while (posi <= posj) {
99 const char *s1 = utf8_decode(s + posi, NULL, !lax);
100 if (s1 == NULL) { /* conversion error? */
101 luaL_pushfail(L); /* return fail ... */
102 lua_pushinteger(L, posi + 1); /* ... and current position */
103 return 2;
104 }
105 posi = ct_diff2S(s1 - s);
106 n++;
107 }
108 lua_pushinteger(L, n);
109 return 1;
110}
111
112
113/*

Callers

nothing calls this directly

Calls 6

luaL_checklstringFunction · 0.70
u_posrelatFunction · 0.70
luaL_optintegerFunction · 0.70
lua_tobooleanFunction · 0.70
utf8_decodeFunction · 0.70
lua_pushintegerFunction · 0.70

Tested by

no test coverage detected