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