Skip to content

Commit

Permalink
GUIEnter event not found in Turkish locale
Browse files Browse the repository at this point in the history
Problem:   GUIEnter not found in Turkish locale
           (James McCoy, after v9.1.0256, the issue was there before,
            but v9.1.0256 made it more apparent)
Solution:  explicitly compare autocommand events by ASCII value and
           ignoring locale, because according to the documentation,
           events are case insensitive (:h autocommand-events)

fixes: vim#15574

Signed-off-by: Christian Brabandt <[email protected]>
  • Loading branch information
chrisbra committed Aug 31, 2024
1 parent 3c9fcb0 commit 5e76487
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/misc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3100,14 +3100,14 @@ cmp_keyvalue_value_i(const void *a, const void *b)
return STRICMP(kv1->value, kv2->value);
}

// compare two keyvalue_T structs by case insensitive value
// compare two keyvalue_T structs by case insensitive ASCII value
// with length
int
cmp_keyvalue_value_ni(const void *a, const void *b)
{
keyvalue_T *kv1 = (keyvalue_T *)a;
keyvalue_T *kv2 = (keyvalue_T *)b;

return STRNICMP(kv1->value, kv2->value, MAX(kv1->length, kv2->length));
return vim_strnicmp_asc(kv1->value, kv2->value, MAX(kv1->length, kv2->length));
}

1 change: 1 addition & 0 deletions src/proto/strings.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void vim_strcat(char_u *to, char_u *from, size_t tosize);
size_t vim_strlen_maxlen(char *s, size_t maxlen);
int vim_stricmp(char *s1, char *s2);
int vim_strnicmp(char *s1, char *s2, size_t len);
int vim_strnicmp_asc(char *s1, char *s2, size_t len);
char_u *vim_strchr(char_u *string, int c);
char_u *vim_strbyte(char_u *string, int c);
char_u *vim_strrchr(char_u *string, int c);
Expand Down
27 changes: 27 additions & 0 deletions src/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,33 @@ vim_strnicmp(char *s1, char *s2, size_t len)
}
#endif

/*
* Compare two ASCII strings, for length "len", ignoring case, ignoring locale
* (mostly matters for turkish locale where i I might be different).
* return 0 for match, < 0 for smaller, > 0 for bigger
*/
int
vim_strnicmp_asc(char *s1, char *s2, size_t len)
{
int i;
int save_cmp_flags = cmp_flags;

cmp_flags |= CMP_KEEPASCII; // compare by ASCII value, ignoring locale
while (len > 0)
{
i = vim_tolower(*s1) - vim_tolower(*s2);
if (i != 0)
break; // this character is different
if (*s1 == NUL)
break; // strings match until NUL
++s1;
++s2;
--len;
}
cmp_flags = save_cmp_flags;
return i;
}

/*
* Search for first occurrence of "c" in "string".
* Version of strchr() that handles unsigned char strings with characters from
Expand Down
19 changes: 19 additions & 0 deletions src/testdir/test_autocmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4863,5 +4863,24 @@ func Test_WinNewPre_crash()
let &cmdheight=_cmdheight
endfunc

" The specifics of the turkish locale may
" cause that Vim will not treat the GuiEnter autocommand
" as case insensitive and instead issues an error
func Test_GuiEnter_Turkish_locale()
try
let lng = v:lang
lang tr_TR.UTF-8
let result = execute(':au GuiEnter')
call assert_equal("\n--- Autocommands ---", result)
let result = execute(':au GUIENTER')
call assert_equal("\n--- Autocommands ---", result)
let result = execute(':au guienter')
call assert_equal("\n--- Autocommands ---", result)
exe ":lang" lng
catch /E197:/
" can't use Turkish locale
throw 'Skipped: Turkish locale not available'
endtry
endfunc

" vim: shiftwidth=2 sts=2 expandtab

0 comments on commit 5e76487

Please sign in to comment.