diff --git a/text-regex-tre.c b/text-regex-tre.c index eccbafbc4..db32d6d9e 100644 --- a/text-regex-tre.c +++ b/text-regex-tre.c @@ -120,8 +120,11 @@ void text_regex_free(Regex *r) { free(r); } -int text_regex_compile(Regex *regex, const char *string, int cflags) { - int r = tre_regcomp(®ex->regex, string, cflags); +int text_regex_compile(Regex *regex, const char *string, size_t len, int cflags) { + int r = len > 0 + ? tre_regncomp(®ex->regex, string, len, cflags) + : tre_regcomp(®ex->regex, string, cflags); + if (r) tre_regcomp(®ex->regex, "\0\0", 0); return r; diff --git a/text-regex.c b/text-regex.c index 7c6812eff..e728de499 100644 --- a/text-regex.c +++ b/text-regex.c @@ -15,7 +15,7 @@ Regex *text_regex_new(void) { return r; } -int text_regex_compile(Regex *regex, const char *string, int cflags) { +int text_regex_compile(Regex *regex, const char *string, size_t len, int cflags) { int r = regcomp(®ex->regex, string, cflags); if (r) regcomp(®ex->regex, "\0\0", 0); diff --git a/text-regex.h b/text-regex.h index dd87c1cb4..031db0117 100644 --- a/text-regex.h +++ b/text-regex.h @@ -15,7 +15,7 @@ typedef struct Regex Regex; typedef Filerange RegexMatch; Regex *text_regex_new(void); -int text_regex_compile(Regex*, const char *pattern, int cflags); +int text_regex_compile(Regex*, const char *pattern, size_t len, int cflags); size_t text_regex_nsub(Regex*); void text_regex_free(Regex*); int text_regex_match(Regex*, const char *data, int eflags); diff --git a/vis-prompt.c b/vis-prompt.c index bf1aeb22d..c2fbf9c1d 100644 --- a/vis-prompt.c +++ b/vis-prompt.c @@ -64,7 +64,7 @@ static const char *prompt_enter(Vis *vis, const char *keys, const Arg *arg) { else if (prompt->file == vis->search_file) pattern = "^(/|\\?)"; int cflags = REG_EXTENDED|REG_NEWLINE|(REG_ICASE*vis->ignorecase); - if (pattern && regex && text_regex_compile(regex, pattern, cflags) == 0) { + if (pattern && regex && text_regex_compile(regex, pattern, 0, cflags) == 0) { size_t end = text_line_end(txt, pos); size_t prev = text_search_backward(txt, end, regex); if (prev > pos) diff --git a/vis.c b/vis.c index 7d3dd6a96..002af2144 100644 --- a/vis.c +++ b/vis.c @@ -1579,17 +1579,19 @@ void vis_insert_nl(Vis *vis) { } Regex *vis_regex(Vis *vis, const char *pattern) { - if (!pattern && !(pattern = register_get(vis, &vis->registers[VIS_REG_SEARCH], NULL))) + size_t len = 0; + if (!pattern && !(pattern = register_get(vis, &vis->registers[VIS_REG_SEARCH], &len))) return NULL; Regex *regex = text_regex_new(); if (!regex) return NULL; int cflags = REG_EXTENDED|REG_NEWLINE|(REG_ICASE*vis->ignorecase); - if (text_regex_compile(regex, pattern, cflags) != 0) { + if (text_regex_compile(regex, pattern, len, cflags) != 0) { text_regex_free(regex); return NULL; } - register_put0(vis, &vis->registers[VIS_REG_SEARCH], pattern); + if (len == 0) + register_put0(vis, &vis->registers[VIS_REG_SEARCH], pattern); return regex; }