diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 12:00:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-05 12:00:26 +0800 |
commit | 50048051565f84b8b75a50f4cfdc5147f861e42b (patch) | |
tree | edf413e2f839c19f48dcd93be5c76afa0cf597e3 /src/nvim/regexp.c | |
parent | 81722896e4a6d17dbf33325d344253e44a11e9ed (diff) | |
parent | 199c7c28989a3c36447ef56b71c7b84756950a11 (diff) | |
download | rneovim-50048051565f84b8b75a50f4cfdc5147f861e42b.tar.gz rneovim-50048051565f84b8b75a50f4cfdc5147f861e42b.tar.bz2 rneovim-50048051565f84b8b75a50f4cfdc5147f861e42b.zip |
Merge pull request #20939 from zeertzjq/vim-8.2.0502
vim-patch:8.2.{0502,0612}
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r-- | src/nvim/regexp.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index d6f207a248..68ffc70457 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -481,13 +481,33 @@ static char_u *skip_anyof(char *p) } /// Skip past regular expression. -/// Stop at end of "startp" or where "dirc" is found ('/', '?', etc). +/// Stop at end of "startp" or where "delim" is found ('/', '?', etc). /// Take care of characters with a backslash in front of it. /// Skip strings inside [ and ]. +char *skip_regexp(char *startp, int delim, int magic) +{ + return skip_regexp_ex(startp, delim, magic, NULL, NULL); +} + +/// Call skip_regexp() and when the delimiter does not match give an error and +/// return NULL. +char *skip_regexp_err(char *startp, int delim, int magic) +{ + char *p = skip_regexp(startp, delim, magic); + + if (*p != delim) { + semsg(_("E654: missing delimiter after search pattern: %s"), startp); + return NULL; + } + return p; +} + +/// skip_regexp() with extra arguments: /// When "newp" is not NULL and "dirc" is '?', make an allocated copy of the /// expression and change "\?" to "?". If "*newp" is not NULL the expression /// is changed in-place. -char *skip_regexp(char *startp, int dirc, int magic, char **newp) +/// If a "\?" is changed to "?" then "dropped" is incremented, unless NULL. +char *skip_regexp_ex(char *startp, int dirc, int magic, char **newp, int *dropped) { int mymagic; char *p = startp; @@ -516,6 +536,9 @@ char *skip_regexp(char *startp, int dirc, int magic, char **newp) *newp = xstrdup(startp); p = *newp + (p - startp); } + if (dropped != NULL) { + (*dropped)++; + } STRMOVE(p, p + 1); } else { p++; // skip next character |