-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vis: fix search wrapping bugs #787
Conversation
1) “$” matches in the middle of the text. visvis ^ - standing here \/ - at first we search forward-\ \_/ - wrap, if nothing found <---/ After wrapping, in the second range “$” will treat end of the range as EOL so “/vis$” will wisely match and moves cursor to the first column. 2) No match after wrapping. vissssss ^^ - standing here or here \\____/ - search this before wrapping ---\ V - search range after wrapping <--/ “/vis” will *not* match (after wrapping), because it crosses ranges. --- So the real solution would be that instead of the end position, the start position of the possible match should be limited because a match can cross the search ranges. To keep things simple, simply search two whole text after wrapping. visvis \____/
Thanks, there is a more general problem though. The regex anchors |
My first thought was that, but think about what if:
For me it appeared to be the simplest solution, everything other would make the handling of this/these edge-case(s) unnecessarily complicated. And it goes through the text (absolutely at most) twice only if no matches found at all. |
I agree that it is more complex and requires additional checks. However, currently the anchors match immediately even when they shouldn't. For example searching for
An analogous problem exists for backward searches with |
Give it a try: vis/fix-search-anchors. It seems it's working with POSIX regexps, but I didn't test it with |
Previously, searches wrapping around did not report any results if they started from within the eventual match. Fix this by enlarging the search area to the whole text after reaching the first boundary. See also #787.
Thanks, it seems more tricky than I initially thought. I think the logic about the |
(Works with any text.) Try
I also found that advancing to the next non-zero char could be simplified to: /* No need for `len` and `junk`. */
while (cur != end) {
...
/* rawmemchr() is non-standard but we already require _GNU_SOURCE because of memrchr() */
cur = rawmemchr(cur, '\0'); /* Knowing that buf is always zero-terminated. */
while (*cur == '\0' && cur < end)
++cur;
eflags |= REG_NOTBOL; /* Surely not line beginning if the previous char was NUL. */
} |
Thanks, point 1. should be fixed by b416a91? And yes searching in binary files, will still show some oddities. |
Previously, searches wrapping around did not report any results if they started from within the eventual match. Fix this by enlarging the search area to the whole text after reaching the first boundary. See also martanne#787.
See commit message.