** codepoint(s, [i, [j [, lax]]]) -> returns codepoints for all ** characters that start in the range [i,j] */
| 124 | ** characters that start in the range [i,j] |
| 125 | */ |
| 126 | static 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 | |
| 155 | static void pushutfchar (lua_State *L, int arg) { |
nothing calls this directly
no test coverage detected