Skip to content

Commit

Permalink
patch 9.1.0297: Patch 9.1.0296 causes too many issues
Browse files Browse the repository at this point in the history
Problem:  Patch 9.1.0296 causes too many issues
          (Tony Mechelynck, @chdiza, CI)
Solution: Back out the change for now

Revert "patch 9.1.0296: regexp: engines do not handle case-folding well"

This reverts commit 7a27c10 it causes
issues with syntax highlighting and breaks the FreeBSD and MacOS CI. It
needs more work.

fixes: #14487

Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
chrisbra committed Apr 10, 2024
1 parent 49f1e19 commit c97f4d6
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 64 deletions.
9 changes: 0 additions & 9 deletions src/mbyte.c
Expand Up @@ -3800,15 +3800,6 @@ utf_strnicmp(
* Returns zero if s1 and s2 are equal (ignoring case), the difference between
* two characters otherwise.
*/
int
mb_strnicmp2(char_u *s1, char_u *s2, int n1, int n2)
{
if (n1 == n2 || !enc_utf8)
return mb_strnicmp(s1, s2, n1);
else
return utf_strnicmp(s1, s2, n1, n2);
}

int
mb_strnicmp(char_u *s1, char_u *s2, size_t nn)
{
Expand Down
1 change: 0 additions & 1 deletion src/proto/mbyte.pro
Expand Up @@ -48,7 +48,6 @@ int utf_islower(int a);
int utf_tolower(int a);
int utf_isupper(int a);
int mb_strnicmp(char_u *s1, char_u *s2, size_t nn);
int mb_strnicmp2(char_u *s1, char_u *s2, int n1, int n2);
void show_utf8(void);
int latin_head_off(char_u *base, char_u *p);
int dbcs_screen_head_off(char_u *base, char_u *p);
Expand Down
11 changes: 1 addition & 10 deletions src/regexp.c
Expand Up @@ -1606,9 +1606,7 @@ mb_decompose(int c, int *c1, int *c2, int *c3)
/*
* Compare two strings, ignore case if rex.reg_ic set.
* Return 0 if strings match, non-zero otherwise.
* Correct the length "*n" when composing characters are ignored
* or for utf8 when both utf codepoints are considered equal because of
* case-folding but have different length (e.g. 's' and 'ſ')
* Correct the length "*n" when composing characters are ignored.
*/
static int
cstrncmp(char_u *s1, char_u *s2, int *n)
Expand All @@ -1617,13 +1615,6 @@ cstrncmp(char_u *s1, char_u *s2, int *n)

if (!rex.reg_ic)
result = STRNCMP(s1, s2, *n);
else if (enc_utf8)
{
int l2 = mb_ptr2len(s2);
result = MB_STRNICMP2(s1, s2, *n, l2);
if (result == 0 && l2 < *n)
*n = l2;
}
else
result = MB_STRNICMP(s1, s2, *n);

Expand Down
8 changes: 0 additions & 8 deletions src/regexp_bt.c
Expand Up @@ -3816,14 +3816,6 @@ regmatch(
}
}
}
else if (enc_utf8)
{
if (cstrncmp(opnd, rex.input, &len) != 0)
{
status = RA_NOMATCH;
break;
}
}
else
for (i = 0; i < len; ++i)
if (opnd[i] != rex.input[i])
Expand Down
9 changes: 2 additions & 7 deletions src/regexp_nfa.c
Expand Up @@ -5666,12 +5666,7 @@ find_match_text(colnr_T *startcol, int regstart, char_u *match_text)
for (;;)
{
match = TRUE;
// skip regstart
len2 = MB_CHAR2LEN(regstart);
if (enc_utf8 && len2 > 1 && MB_CHAR2LEN(PTR2CHAR(rex.line + col)) != len2)
// because of case-folding of the previously matched text, we may need
// to skip fewer bytes than mb_char2len(regstart)
len2 = mb_char2len(utf_fold(regstart));
len2 = MB_CHAR2LEN(regstart); // skip regstart
for (len1 = 0; match_text[len1] != NUL; len1 += MB_CHAR2LEN(c1))
{
c1 = PTR2CHAR(match_text + len1);
Expand Down Expand Up @@ -7508,7 +7503,7 @@ nfa_regexec_both(

// If match_text is set it contains the full text that must match.
// Nothing else to try. Doesn't handle combining chars well.
if (prog->match_text != NULL && *prog->match_text != NUL && !rex.reg_icombine)
if (prog->match_text != NULL && !rex.reg_icombine)
{
retval = find_match_text(&col, prog->regstart, prog->match_text);
if (REG_MULTI)
Expand Down
28 changes: 0 additions & 28 deletions src/testdir/test_regexp_utf8.vim
Expand Up @@ -587,32 +587,4 @@ func Test_combining_chars_in_collection()
bw!
endfunc

func Test_search_multibyte_match_ascii()
new
" Match single '鰱' and 's'
call setline(1, 'das abc heraus abc 鰱ich abc 鰱ind')
for i in range(0, 2)
exe "set re="..i
let ic_match = matchbufline('%', '\c\%u17f', 1, '$')->mapnew({idx, val -> val.text})
let noic_match = matchbufline('%', '\C\%u17f', 1, '$')->mapnew({idx, val -> val.text})
call assert_equal(['s', 's', '',''], ic_match, "Ignorecase Regex-engine: " .. &re)
call assert_equal(['',''], noic_match, "No-Ignorecase Regex-engine: " .. &re)
endfor
" Match several '鰱鰱' and 'ss'
call setline(1, 'das abc herauss abc 鰱鰱ich abc 鰱ind')
for i in range(0, 2)
exe "set re="..i
let ic_match = matchbufline('%', '\c\%u17f\%u17f', 1, '$')->mapnew({idx, val -> val.text})
let noic_match = matchbufline('%', '\C\%u17f\%u17f', 1, '$')->mapnew({idx, val -> val.text})
let ic_match2 = matchbufline('%', '\c\%u17f\+', 1, '$')->mapnew({idx, val -> val.text})
let noic_match2 = matchbufline('%', '\C\%u17f\+', 1, '$')->mapnew({idx, val -> val.text})

call assert_equal(['ss', '鰱鰱'], ic_match, "Ignorecase Regex-engine: " .. &re)
call assert_equal(['鰱鰱'], noic_match, "No-Ignorecase Regex-engine: " .. &re)
call assert_equal(['s', 'ss', '鰱鰱', ''], ic_match2, "Ignorecase Regex-engine: " .. &re)
call assert_equal(['鰱鰱',''], noic_match2, "No-Ignorecase Regex-engine: " .. &re)
endfor
bw!
endfunc

" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
297,
/**/
296,
/**/
Expand Down
1 change: 0 additions & 1 deletion src/vim.h
Expand Up @@ -1751,7 +1751,6 @@ void *vim_memset(void *, int, size_t);

# define MB_STRICMP(d, s) mb_strnicmp((char_u *)(d), (char_u *)(s), (int)MAXCOL)
# define MB_STRNICMP(d, s, n) mb_strnicmp((char_u *)(d), (char_u *)(s), (int)(n))
# define MB_STRNICMP2(d, s, n1, n2) mb_strnicmp2((char_u *)(d), (char_u *)(s), (int)(n1), (int)(n2))

#define STRCAT(d, s) strcat((char *)(d), (char *)(s))
#define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n))
Expand Down

0 comments on commit c97f4d6

Please sign in to comment.