diff options
author | Ron Yorston <rmy@pobox.com> | 2021-07-06 07:43:57 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-13 13:50:59 +0200 |
commit | c76c78740a19ed3b1f9c5910313460221096536a (patch) | |
tree | 6f509d6254d369c064d88624baccebdbac2d4678 | |
parent | 2916443ab650b10fd401ceb221d26fa58e2e99b3 (diff) | |
download | busybox-w32-c76c78740a19ed3b1f9c5910313460221096536a.tar.gz busybox-w32-c76c78740a19ed3b1f9c5910313460221096536a.tar.bz2 busybox-w32-c76c78740a19ed3b1f9c5910313460221096536a.zip |
vi: improve handling of anchored searches
Suppose we search for a git conflict marker '<<<<<<< HEAD' using
the command '/^<<<'. Using 'n' to go to the next match finds
'<<<' on the current line, apparently ignoring the '^' anchor.
Set a flag in the compiled regular expression to indicate that the
start of the string should not be considered a beginning-of-line
anchor. An exception has to be made when the search starts from
the beginning of the file. Make a similar change for end-of-line
anchors.
This doesn't affect a default build with VI_REGEX_SEARCH disabled.
When it's enabled:
function old new delta
char_search 247 285 +38
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/editors/vi.c b/editors/vi.c index 34d577e90..2941b8ae4 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -2384,6 +2384,8 @@ static char *char_search(char *p, const char *pat, int dir_and_range) | |||
2384 | 2384 | ||
2385 | memset(&preg, 0, sizeof(preg)); | 2385 | memset(&preg, 0, sizeof(preg)); |
2386 | err = re_compile_pattern(pat, strlen(pat), &preg); | 2386 | err = re_compile_pattern(pat, strlen(pat), &preg); |
2387 | preg.not_bol = p != text; | ||
2388 | preg.not_eol = p != end - 1; | ||
2387 | if (err != NULL) { | 2389 | if (err != NULL) { |
2388 | status_line_bold("bad search pattern '%s': %s", pat, err); | 2390 | status_line_bold("bad search pattern '%s': %s", pat, err); |
2389 | return p; | 2391 | return p; |