| 222 | |
| 223 | |
| 224 | static int iter_aux (lua_State *L, int strict) { |
| 225 | size_t len; |
| 226 | const char *s = luaL_checklstring(L, 1, &len); |
| 227 | lua_Integer n = lua_tointeger(L, 2) - 1; |
| 228 | if (n < 0) /* first iteration? */ |
| 229 | n = 0; /* start from here */ |
| 230 | else if (n < (lua_Integer)len) { |
| 231 | n++; /* skip current byte */ |
| 232 | while (iscont(s + n)) n++; /* and its continuations */ |
| 233 | } |
| 234 | if (n >= (lua_Integer)len) |
| 235 | return 0; /* no more codepoints */ |
| 236 | else { |
| 237 | utfint code; |
| 238 | const char *next = utf8_decode(s + n, &code, strict); |
| 239 | if (next == NULL) |
| 240 | return luaL_error(L, "invalid UTF-8 code"); |
| 241 | lua_pushinteger(L, n + 1); |
| 242 | lua_pushinteger(L, code); |
| 243 | return 2; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | |
| 248 | static int iter_auxstrict (lua_State *L) { |
no test coverage detected