vim-patch:7.4.293

Problem:    It is not possible to ignore composing characters at a
            specific point in a pattern.
Solution:   Add the %C item.

https://code.google.com/p/vim/source/detail?r=10fc95f48546f438648b8357062e93c9c2c0a377
This commit is contained in:
Damián Silvani
2014-07-20 13:15:21 -03:00
parent 6d45309797
commit 9ea28e1903
3 changed files with 53 additions and 10 deletions

View File

@@ -85,6 +85,7 @@ enum {
NFA_COMPOSING, /* Next nodes in NFA are part of the
composing multibyte char */
NFA_END_COMPOSING, /* End of a composing char in the NFA */
NFA_ANY_COMPOSING, // \%C: Any composing characters.
NFA_OPT_CHARS, /* \%[abc] */
/* The following are used only in the postfix form, not in the NFA */
@@ -1350,6 +1351,10 @@ static int nfa_regatom(void)
EMIT(NFA_VISUAL);
break;
case 'C':
EMIT(NFA_ANY_COMPOSING);
break;
case '[':
{
int n;
@@ -2259,6 +2264,7 @@ static void nfa_set_code(int c)
case NFA_MARK_LT: STRCPY(code, "NFA_MARK_LT "); break;
case NFA_CURSOR: STRCPY(code, "NFA_CURSOR "); break;
case NFA_VISUAL: STRCPY(code, "NFA_VISUAL "); break;
case NFA_ANY_COMPOSING: STRCPY(code, "NFA_ANY_COMPOSING "); break;
case NFA_STAR: STRCPY(code, "NFA_STAR "); break;
case NFA_STAR_NONGREEDY: STRCPY(code, "NFA_STAR_NONGREEDY "); break;
@@ -2716,6 +2722,7 @@ static int nfa_max_width(nfa_state_T *startstate, int depth)
case NFA_NLOWER_IC:
case NFA_UPPER_IC:
case NFA_NUPPER_IC:
case NFA_ANY_COMPOSING:
/* possibly non-ascii */
if (has_mbyte)
len += 3;
@@ -3714,6 +3721,7 @@ static int match_follows(nfa_state_T *startstate, int depth)
continue;
case NFA_ANY:
case NFA_ANY_COMPOSING:
case NFA_IDENT:
case NFA_SIDENT:
case NFA_KWORD:
@@ -3943,7 +3951,7 @@ skip_add:
#endif
switch (state->c) {
case NFA_MATCH:
nfa_match = TRUE;
//nfa_match = TRUE;
break;
case NFA_SPLIT:
@@ -4573,6 +4581,7 @@ static int failure_chance(nfa_state_T *state, int depth)
case NFA_MATCH:
case NFA_MCLOSE:
case NFA_ANY_COMPOSING:
/* empty match works always */
return 0;
@@ -4951,6 +4960,11 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
switch (t->state->c) {
case NFA_MATCH:
{
// If the match ends before a composing characters and
// ireg_icombine is not set, that is not really a match.
if (enc_utf8 && !ireg_icombine && utf_iscomposing(curc)) {
break;
}
nfa_match = TRUE;
copy_sub(&submatch->norm, &t->subs.norm);
if (nfa_has_zsubexpr)
@@ -5430,6 +5444,18 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
}
break;
case NFA_ANY_COMPOSING:
// On a composing character skip over it. Otherwise do
// nothing. Always matches.
if (enc_utf8 && utf_iscomposing(curc)) {
add_off = clen;
} else {
add_here = TRUE;
add_off = 0;
}
add_state = t->state->out;
break;
/*
* Character classes like \a for alpha, \d for digit etc.
*/
@@ -5769,12 +5795,13 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
if (!result && ireg_ic)
result = vim_tolower(c) == vim_tolower(curc);
/* If there is a composing character which is not being
* ignored there can be no match. Match with composing
* character uses NFA_COMPOSING above. */
if (result && enc_utf8 && !ireg_icombine
&& clen != utf_char2len(curc))
result = FALSE;
// If ireg_icombine is not set only skip over the character
// itself. When it is set skip over composing characters.
if (result && enc_utf8 && !ireg_icombine) {
clen = utf_char2len(curc);
}
ADD_STATE_IF_MATCH(t->state);
break;
}