| 199 | |
| 200 | |
| 201 | static int iter_aux (lua_State *L) { |
| 202 | size_t len; |
| 203 | const char *s = luaL_checklstring(L, 1, &len); |
| 204 | lua_Integer n = lua_tointeger(L, 2) - 1; |
| 205 | if (n < 0) /* first iteration? */ |
| 206 | n = 0; /* start from here */ |
| 207 | else if (n < (lua_Integer)len) { |
| 208 | n++; /* skip current byte */ |
| 209 | while (iscont(s + n)) n++; /* and its continuations */ |
| 210 | } |
| 211 | if (n >= (lua_Integer)len) |
| 212 | return 0; /* no more codepoints */ |
| 213 | else { |
| 214 | int code; |
| 215 | const char *next = utf8_decode(s + n, &code); |
| 216 | if (next == NULL || iscont(next)) |
| 217 | return luaL_error(L, "invalid UTF-8 code"); |
| 218 | lua_pushinteger(L, n + 1); |
| 219 | lua_pushinteger(L, code); |
| 220 | return 2; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | |
| 225 | static int iter_codes (lua_State *L) { |
nothing calls this directly
no test coverage detected