Closed arnoldrobbins closed 8 months ago
Thanks @arnoldrobbins for this. BTW, you don't really need a new loop variable for this, you could just operate directly on r.len since you are headed for return regardless.
It's incorrect to assume that there will be only one rune's worth of bytes to put back. If the automaton went looking for a longer match, failed to find it, and settled for a shorter one, there could be much more after the match.
$ printf aaaZZZbbb | ./correct.out '{print} END {print NR}' RS='ZZZ(bbbb)?'
aaa
bbb
2
$ printf aaaZZZbbb | ./broken.out '{print} END {print NR}' RS='ZZZ(bbbb)?'
aaa
1
@mpinjr I see. If your PR handles this then I'm OK with going with it. @plan9 You should probably take his PR and close mine.
Use sane code after finding the end of the match to put back the last rune read and terminate the buffer. Fixes https://github.com/onetrueawk/awk/issues/212.