** codepoint(s, [i, [j [, lax]]]) -> returns codepoints for all ** characters that start in the range [i,j] */
| 115 | ** characters that start in the range [i,j] |
| 116 | */ |
| 117 | static int codepoint (lua_State *L) { |
| 118 | size_t len; |
| 119 | const char *s = luaL_checklstring(L, 1, &len); |
| 120 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); |
| 121 | lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len); |
| 122 | int lax = lua_toboolean(L, 4); |
| 123 | int n; |
| 124 | const char *se; |
| 125 | luaL_argcheck(L, posi >= 1, 2, "out of bounds"); |
| 126 | luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of bounds"); |
| 127 | if (posi > pose) return 0; /* empty interval; return no values */ |
| 128 | if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */ |
| 129 | return luaL_error(L, "string slice too long"); |
| 130 | n = (int)(pose - posi) + 1; /* upper bound for number of returns */ |
| 131 | luaL_checkstack(L, n, "string slice too long"); |
| 132 | n = 0; /* count the number of returns */ |
| 133 | se = s + pose; /* string end */ |
| 134 | for (s += posi - 1; s < se;) { |
| 135 | l_uint32 code; |
| 136 | s = utf8_decode(s, &code, !lax); |
| 137 | if (s == NULL) |
| 138 | return luaL_error(L, MSGInvalid); |
| 139 | lua_pushinteger(L, l_castU2S(code)); |
| 140 | n++; |
| 141 | } |
| 142 | return n; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | static void pushutfchar (lua_State *L, int arg) { |
nothing calls this directly
no test coverage detected