diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/charset.c | 11 | ||||
-rw-r--r-- | src/nvim/regexp_nfa.c | 52 | ||||
-rw-r--r-- | src/nvim/search.c | 50 |
3 files changed, 54 insertions, 59 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 2a76983870..9c63eca1f2 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1791,7 +1791,6 @@ void vim_str2nr(char_u *start, int *prep, int *len, int pre = 0; // default is decimal int negative = false; unsigned long un = 0; - int n = 0; if (ptr[0] == '-') { negative = true; @@ -1818,7 +1817,7 @@ void vim_str2nr(char_u *start, int *prep, int *len, if (dooct) { // Don't interpret "0", "08" or "0129" as octal. - for (n = 1; ascii_isdigit(ptr[n]); ++n) { + for (int n = 1; ascii_isdigit(ptr[n]); ++n) { if (ptr[n] > '7') { // can't be octal pre = 0; @@ -1836,9 +1835,6 @@ void vim_str2nr(char_u *start, int *prep, int *len, // Do the string-to-numeric conversion "manually" to avoid sscanf quirks. if ((pre == 'B') || (pre == 'b') || (dobin > 1)) { // bin - if (pre != 0) { - n += 2; // skip over "0b" - } while ('0' <= *ptr && *ptr <= '1') { un = 2 * un + (unsigned long)(*ptr - '0'); ptr++; @@ -1849,11 +1845,8 @@ void vim_str2nr(char_u *start, int *prep, int *len, un = 8 * un + (unsigned long)(*ptr - '0'); ptr++; } - } else if (pre != 0 || dohex > 1) { + } else if ((pre == 'X') || (pre == 'x') || dohex > 1) { // hex - if (pre != 0) { - n += 2; // skip over "0x" - } while (ascii_isxdigit(*ptr)) { un = 16 * un + (unsigned long)hex2nr(*ptr); ptr++; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 1fd024a062..4020fa6e28 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -4762,48 +4762,54 @@ static int skip_to_start(int c, colnr_T *colp) */ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text) { - colnr_T col = startcol; - int c1, c2; - int len1, len2; - int match; +#define PTR2LEN(x) enc_utf8 ? utf_ptr2len(x) : MB_PTR2LEN(x) - for (;; ) { - match = TRUE; - len2 = MB_CHAR2LEN(regstart); /* skip regstart */ - for (len1 = 0; match_text[len1] != NUL; len1 += MB_CHAR2LEN(c1)) { - c1 = PTR2CHAR(match_text + len1); - c2 = PTR2CHAR(regline + col + len2); - if (c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2))) { - match = FALSE; + colnr_T col = startcol; + int regstart_len = PTR2LEN(regline + startcol); + + for (;;) { + bool match = true; + char_u *s1 = match_text; + char_u *s2 = regline + col + regstart_len; // skip regstart + while (*s1) { + int c1_len = PTR2LEN(s1); + int c1 = PTR2CHAR(s1); + int c2_len = PTR2LEN(s2); + int c2 = PTR2CHAR(s2); + + if ((c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2))) || + c1_len != c2_len) { + match = false; break; } - len2 += MB_CHAR2LEN(c2); + s1 += c1_len; + s2 += c2_len; } if (match - /* check that no composing char follows */ - && !(enc_utf8 - && STRLEN(regline) > (size_t)(col + len2) - && utf_iscomposing(PTR2CHAR(regline + col + len2))) - ) { + // check that no composing char follows + && !(enc_utf8 && utf_iscomposing(PTR2CHAR(s2)))) { cleanup_subexpr(); if (REG_MULTI) { reg_startpos[0].lnum = reglnum; reg_startpos[0].col = col; reg_endpos[0].lnum = reglnum; - reg_endpos[0].col = col + len2; + reg_endpos[0].col = s2 - regline; } else { reg_startp[0] = regline + col; - reg_endp[0] = regline + col + len2; + reg_endp[0] = s2; } return 1L; } - /* Try finding regstart after the current match. */ - col += MB_CHAR2LEN(regstart); /* skip regstart */ - if (skip_to_start(regstart, &col) == FAIL) + // Try finding regstart after the current match. + col += regstart_len; // skip regstart + if (skip_to_start(regstart, &col) == FAIL) { break; + } } return 0L; + +#undef PTR2LEN } /* diff --git a/src/nvim/search.c b/src/nvim/search.c index 18a72524cb..d393ee7d02 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -621,43 +621,39 @@ int searchit( break; } matchcol = endpos.col; - /* for empty match: advance one char */ - if (matchcol == matchpos.col - && ptr[matchcol] != NUL) { - if (has_mbyte) - matchcol += - (*mb_ptr2len)(ptr + matchcol); - else - ++matchcol; - } + // for empty match (matchcol == matchpos.col): advance one char } else { + // Prepare to start after first matched character. matchcol = matchpos.col; - if (ptr[matchcol] != NUL) { - if (has_mbyte) - matchcol += (*mb_ptr2len)(ptr - + matchcol); - else - ++matchcol; - } } - if (matchcol == 0 && (options & SEARCH_START)) + + if (matchcol == matchpos.col && ptr[matchcol] != NUL) { + matchcol += MB_PTR2LEN(ptr + matchcol); + } + + if (matchcol == 0 && (options & SEARCH_START)) { break; - if (STRLEN(ptr) <= (size_t)matchcol || ptr[matchcol] == NUL - || (nmatched = vim_regexec_multi(®match, - win, buf, lnum + matchpos.lnum, - matchcol, - tm - )) == 0) { - match_ok = FALSE; + } + + if (ptr[matchcol] == NUL || + (nmatched = vim_regexec_multi(®match, win, buf, lnum, + matchcol, tm)) == 0) { + match_ok = false; break; } matchpos = regmatch.startpos[0]; endpos = regmatch.endpos[0]; submatch = first_submatch(®match); - /* Need to get the line pointer again, a - * multi-line search may have made it invalid. */ - ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE); + // This while-loop only works with matchpos.lnum == 0. + // For bigger values the next line pointer ptr might not be a + // buffer line. + if (matchpos.lnum != 0) { + break; + } + // Need to get the line pointer again, a multi-line search may + // have made it invalid. + ptr = ml_get_buf(buf, lnum, false); } if (!match_ok) continue; |