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)
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 9ebd2df..99d01c4 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -12503,39 +12503,8 @@
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]));
}
/*