vim-patch:8.2.0938: NFA regexp uses tolower ()to compare ignore-case

Problem:    NFA regexp uses tolower() to compare ignore-case. (Thayne McCombs)
Solution:   Use utf_fold() when possible. (ref. neovim vim/vim#12456)
59de417b90
This commit is contained in:
Jan Edmund Lazo
2020-06-09 18:17:47 -04:00
parent b7cae2bca3
commit 33985a3a15
2 changed files with 28 additions and 8 deletions

View File

@@ -4960,7 +4960,7 @@ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text)
int c2_len = PTR2LEN(s2);
int c2 = PTR2CHAR(s2);
if ((c1 != c2 && (!rex.reg_ic || mb_tolower(c1) != mb_tolower(c2)))
if ((c1 != c2 && (!rex.reg_ic || utf_fold(c1) != utf_fold(c2)))
|| c1_len != c2_len) {
match = false;
break;
@@ -5682,11 +5682,11 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
break;
}
if (rex.reg_ic) {
int curc_low = mb_tolower(curc);
int curc_low = utf_fold(curc);
int done = false;
for (; c1 <= c2; c1++) {
if (mb_tolower(c1) == curc_low) {
if (utf_fold(c1) == curc_low) {
result = result_if_matched;
done = TRUE;
break;
@@ -5698,8 +5698,8 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
}
} else if (state->c < 0 ? check_char_class(state->c, curc)
: (curc == state->c
|| (rex.reg_ic && mb_tolower(curc)
== mb_tolower(state->c)))) {
|| (rex.reg_ic
&& utf_fold(curc) == utf_fold(state->c)))) {
result = result_if_matched;
break;
}
@@ -6106,7 +6106,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
result = (c == curc);
if (!result && rex.reg_ic) {
result = mb_tolower(c) == mb_tolower(curc);
result = utf_fold(c) == utf_fold(curc);
}
// If rex.reg_icombine is not set only skip over the character
@@ -6260,8 +6260,9 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
// Checking if the required start character matches is
// cheaper than adding a state that won't match.
c = PTR2CHAR(reginput + clen);
if (c != prog->regstart && (!rex.reg_ic || mb_tolower(c)
!= mb_tolower(prog->regstart))) {
if (c != prog->regstart
&& (!rex.reg_ic
|| utf_fold(c) != utf_fold(prog->regstart))) {
#ifdef REGEXP_DEBUG
fprintf(log_fd,
" Skipping start state, regstart does not match\n");