mirror of
https://github.com/vim/vim.git
synced 2025-10-05 05:34:07 -04:00
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Problem: Multi-byte chars do not work properly with "%.*S" in printf(). Solution: Use mb_ptr2cells(). Daniel Hahler, closes #4989)
This commit is contained in:
@@ -4405,12 +4405,16 @@ vim_vsnprintf_typval(
|
||||
- mb_string2cells((char_u *)str_arg, -1);
|
||||
if (precision)
|
||||
{
|
||||
char_u *p1 = (char_u *)str_arg;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < precision && *p1; i++)
|
||||
p1 += mb_ptr2len(p1);
|
||||
char_u *p1;
|
||||
size_t i = 0;
|
||||
|
||||
for (p1 = (char_u *)str_arg; *p1;
|
||||
p1 += mb_ptr2len(p1))
|
||||
{
|
||||
i += (size_t)mb_ptr2cells(p1);
|
||||
if (i > precision)
|
||||
break;
|
||||
}
|
||||
str_arg_l = precision = p1 - (char_u *)str_arg;
|
||||
}
|
||||
}
|
||||
|
@@ -248,6 +248,9 @@ function Test_printf_misc()
|
||||
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))
|
||||
endfunc
|
||||
|
||||
|
@@ -757,6 +757,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
2083,
|
||||
/**/
|
||||
2082,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user