mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 11:15:14 -07:00
vim-patch:8.1.2083: multi-byte chars do not work properly with "%.*S" in printf() (#11106)
Problem: Multi-byte chars do not work properly with "%.*S" in printf().
Solution: Use mb_ptr2cells(). Daniel Hahler, closes vim/vim#4989)
ce0fac2897
This commit is contained in:
parent
fe9d54f418
commit
0d9a3c86a1
@ -953,11 +953,17 @@ int vim_vsnprintf_typval(
|
|||||||
- mb_string2cells((char_u *)str_arg));
|
- mb_string2cells((char_u *)str_arg));
|
||||||
}
|
}
|
||||||
if (precision) {
|
if (precision) {
|
||||||
const char *p1 = str_arg;
|
char_u *p1;
|
||||||
for (size_t i = 0; i < precision && *p1; i++) {
|
size_t i = 0;
|
||||||
p1 += mb_ptr2len((const char_u *)p1);
|
|
||||||
|
for (p1 = (char_u *)str_arg; *p1;
|
||||||
|
p1 += mb_ptr2len(p1)) {
|
||||||
|
i += (size_t)utf_ptr2cells(p1);
|
||||||
|
if (i > precision) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
str_arg_l = precision = (size_t)(p1 - str_arg);
|
str_arg_l = precision = (size_t)(p1 - (char_u *)str_arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -279,6 +279,9 @@ function Test_printf_misc()
|
|||||||
call assert_equal('abc ', printf('%-4s', 'abc'))
|
call assert_equal('abc ', printf('%-4s', 'abc'))
|
||||||
call assert_equal('abc ', printf('%-4S', 'abc'))
|
call assert_equal('abc ', printf('%-4S', 'abc'))
|
||||||
|
|
||||||
|
call assert_equal('🐍', printf('%.2S', '🐍🐍'))
|
||||||
|
call assert_equal('', printf('%.1S', '🐍🐍'))
|
||||||
|
|
||||||
call assert_equal('1%', printf('%d%%', 1))
|
call assert_equal('1%', printf('%d%%', 1))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user