[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] vi: improve handling of anchored searches
From:       Ron Yorston <rmy () pobox ! com>
Date:       2021-07-06 6:43:57
Message-ID: 60e3fbad.TDR4kolQq44wg3vJ%rmy () pobox ! com
[Download RAW message or body]

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>
---
 editors/vi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/editors/vi.c b/editors/vi.c
index 3e91fefbc..f779507fc 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)
 
 	memset(&preg, 0, sizeof(preg));
 	err = re_compile_pattern(pat, strlen(pat), &preg);
+	preg.not_bol = p != text;
+	preg.not_eol = p != end - 1;
 	if (err != NULL) {
 		status_line_bold("bad search pattern '%s': %s", pat, err);
 		return p;
-- 
2.31.1

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic