MCPcopy Create free account
hub / github.com/DFHack/dfhack / codepoint

Function codepoint

depends/lua/src/lutf8lib.c:100–125  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

98** that start in the range [i,j]
99*/
100static int codepoint (lua_State *L) {
101 size_t len;
102 const char *s = luaL_checklstring(L, 1, &len);
103 lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);
104 lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len);
105 int n;
106 const char *se;
107 luaL_argcheck(L, posi >= 1, 2, "out of range");
108 luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range");
109 if (posi > pose) return 0; /* empty interval; return no values */
110 if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */
111 return luaL_error(L, "string slice too long");
112 n = (int)(pose - posi) + 1;
113 luaL_checkstack(L, n, "string slice too long");
114 n = 0;
115 se = s + pose;
116 for (s += posi - 1; s < se;) {
117 int code;
118 s = utf8_decode(s, &code);
119 if (s == NULL)
120 return luaL_error(L, "invalid UTF-8 code");
121 lua_pushinteger(L, code);
122 n++;
123 }
124 return n;
125}
126
127
128static void pushutfchar (lua_State *L, int arg) {

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected