diff options
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r-- | src/nvim/regexp.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index a2589ac431..e0cc25421a 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3436,7 +3436,7 @@ static long bt_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, } /// Match a regexp against a string ("line" points to the string) or multiple -/// lines ("line" is NULL, use reg_getline()). +/// lines (if "line" is NULL, use reg_getline()). /// @return 0 for failure, or number of lines contained in the match. static long bt_regexec_both(char_u *line, colnr_T col, // column to start search @@ -5895,7 +5895,7 @@ static void regdump(char_u *pattern, bt_regprog_T *r) fprintf(f, " count %" PRId64, (int64_t)OPERAND_MIN(s)); s += 4; } else if (op == RE_LNUM || op == RE_COL || op == RE_VCOL) { - /* one int plus comperator */ + // one int plus comparator fprintf(f, " count %" PRId64, (int64_t)OPERAND_MIN(s)); s += 5; } @@ -6665,6 +6665,10 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int len = 0; /* init for GCC */ static char_u *eval_result = NULL; + // We need to keep track of how many backslashes we escape, so that the byte + // counts for `extmark_splice` are correct. + int num_escaped = 0; + // Be paranoid... if ((source == NULL && expr == NULL) || dest == NULL) { EMSG(_(e_null)); @@ -6840,6 +6844,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, // later. Used to insert a literal CR. default: if (backslash) { + num_escaped += 1; if (copy) { *dst = '\\'; } @@ -6979,7 +6984,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, *dst = NUL; exit: - return (int)((dst - dest) + 1); + return (int)((dst - dest) + 1 - num_escaped); } @@ -7139,6 +7144,7 @@ list_T *reg_submatch_list(int no) tv_list_append_string(list, s, (const char *)rsm.sm_match->endp[no] - s); } + tv_list_ref(list); return list; } |