Make empty groups in `regex.gmatch` return their offset (#1325)
This makes `regex.gmatch` behave like `string.gmatch`.
This commit is contained in:
parent
90a7882ed4
commit
757b906ca2
|
@ -91,6 +91,9 @@ static int regex_gmatch_iterator(lua_State *L) {
|
||||||
int total_results = ovector_count * 2;
|
int total_results = ovector_count * 2;
|
||||||
size_t last_offset = 0;
|
size_t last_offset = 0;
|
||||||
for (int i = index; i < total_results; i+=2) {
|
for (int i = index; i < total_results; i+=2) {
|
||||||
|
if (ovector[i] == ovector[i+1])
|
||||||
|
lua_pushinteger(L, ovector[i] + 1);
|
||||||
|
else
|
||||||
lua_pushlstring(L, state->subject+ovector[i], ovector[i+1] - ovector[i]);
|
lua_pushlstring(L, state->subject+ovector[i], ovector[i+1] - ovector[i]);
|
||||||
last_offset = ovector[i+1];
|
last_offset = ovector[i+1];
|
||||||
total++;
|
total++;
|
||||||
|
|
Loading…
Reference in New Issue