Skip to content

Commit

Permalink
Make empty groups in regex.gmatch return their offset (lite-xl#1325)
Browse files Browse the repository at this point in the history
This makes `regex.gmatch` behave like `string.gmatch`.
  • Loading branch information
Guldoman authored Jan 13, 2023
1 parent 6e04a4f commit b89dedf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/api/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ static int regex_gmatch_iterator(lua_State *L) {
int total_results = ovector_count * 2;
size_t last_offset = 0;
for (int i = index; i < total_results; i+=2) {
lua_pushlstring(L, state->subject+ovector[i], ovector[i+1] - ovector[i]);
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]);
last_offset = ovector[i+1];
total++;
}
Expand Down

0 comments on commit b89dedf

Please sign in to comment.