MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / codepoint

Function codepoint

lib/lua/src/lutf8lib.c:126–152  ·  view source on GitHub ↗

** codepoint(s, [i, [j [, lax]]]) -> returns codepoints for all ** characters that start in the range [i,j] */

Source from the content-addressed store, hash-verified

124** characters that start in the range [i,j]
125*/
126static int codepoint (lua_State *L) {
127 size_t len;
128 const char *s = luaL_checklstring(L, 1, &len);
129 lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);
130 lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len);
131 int lax = lua_toboolean(L, 4);
132 int n;
133 const char *se;
134 luaL_argcheck(L, posi >= 1, 2, "out of bounds");
135 luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of bounds");
136 if (posi > pose) return 0; /* empty interval; return no values */
137 if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */
138 return luaL_error(L, "string slice too long");
139 n = (int)(pose - posi) + 1; /* upper bound for number of returns */
140 luaL_checkstack(L, n, "string slice too long");
141 n = 0; /* count the number of returns */
142 se = s + pose; /* string end */
143 for (s += posi - 1; s < se;) {
144 utfint code;
145 s = utf8_decode(s, &code, !lax);
146 if (s == NULL)
147 return luaL_error(L, MSGInvalid);
148 lua_pushinteger(L, code);
149 n++;
150 }
151 return n;
152}
153
154
155static void pushutfchar (lua_State *L, int arg) {

Callers

nothing calls this directly

Calls 8

luaL_checklstringFunction · 0.85
u_posrelatFunction · 0.85
luaL_optintegerFunction · 0.85
lua_tobooleanFunction · 0.85
luaL_errorFunction · 0.85
luaL_checkstackFunction · 0.85
utf8_decodeFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected