0
0
mirror of https://github.com/vim/vim.git synced 2025-10-13 06:54:15 -04:00

patch 8.0.0243: tolower() does not work if the byte count changes

Problem:    When making a character lower case with tolower() changes the byte
            cound, it is not made lower case.
Solution:   Add strlow_save(). (Dominique Pelle, closes #1406)
This commit is contained in:
Bram Moolenaar
2017-01-26 22:51:56 +01:00
parent 65c836e600
commit cc5b22b3bf
5 changed files with 216 additions and 33 deletions

View File

@@ -12503,39 +12503,8 @@ f_timer_stopall(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
static void
f_tolower(typval_T *argvars, typval_T *rettv)
{
char_u *p;
p = vim_strsave(get_tv_string(&argvars[0]));
rettv->v_type = VAR_STRING;
rettv->vval.v_string = p;
if (p != NULL)
while (*p != NUL)
{
#ifdef FEAT_MBYTE
int l;
if (enc_utf8)
{
int c, lc;
c = utf_ptr2char(p);
lc = utf_tolower(c);
l = utf_ptr2len(p);
/* TODO: reallocate string when byte count changes. */
if (utf_char2len(lc) == l)
utf_char2bytes(lc, p);
p += l;
}
else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; /* skip multi-byte character */
else
#endif
{
*p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */
++p;
}
}
rettv->vval.v_string = strlow_save(get_tv_string(&argvars[0]));
}
/*