mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 03:16:31 +00:00
vim-patch:8.2.3630: printf() with %S does not handle multi-byte correctly
Problem: Printf() with %S does not handle multi-byte correctly.
Solution: Count cells instead of bytes. (closes vim/vim#9169, closes vim/vim#7486)
d85fccdfed
This commit is contained in:
@@ -1001,10 +1001,9 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t
|
|||||||
- str_arg);
|
- str_arg);
|
||||||
}
|
}
|
||||||
if (fmt_spec == 'S') {
|
if (fmt_spec == 'S') {
|
||||||
if (min_field_width != 0) {
|
size_t base_width = min_field_width;
|
||||||
min_field_width += (strlen(str_arg)
|
size_t pad_cell = 0;
|
||||||
- mb_string2cells((char_u *)str_arg));
|
|
||||||
}
|
|
||||||
if (precision) {
|
if (precision) {
|
||||||
char_u *p1;
|
char_u *p1;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
@@ -1016,7 +1015,11 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str_arg_l = (size_t)(p1 - (char_u *)str_arg);
|
pad_cell = min_field_width - precision;
|
||||||
|
base_width = str_arg_l = (size_t)(p1 - (char_u *)str_arg);
|
||||||
|
}
|
||||||
|
if (min_field_width != 0) {
|
||||||
|
min_field_width = base_width + pad_cell;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -283,6 +283,11 @@ function Test_printf_misc()
|
|||||||
call assert_equal('🐍', printf('%.2S', '🐍🐍'))
|
call assert_equal('🐍', printf('%.2S', '🐍🐍'))
|
||||||
call assert_equal('', printf('%.1S', '🐍🐍'))
|
call assert_equal('', printf('%.1S', '🐍🐍'))
|
||||||
|
|
||||||
|
call assert_equal('[ あいう]', printf('[%10.6S]', 'あいうえお'))
|
||||||
|
call assert_equal('[ あいうえ]', printf('[%10.8S]', 'あいうえお'))
|
||||||
|
call assert_equal('[あいうえお]', printf('[%10.10S]', 'あいうえお'))
|
||||||
|
call assert_equal('[あいうえお]', printf('[%10.12S]', 'あいうえお'))
|
||||||
|
|
||||||
call assert_equal('1%', printf('%d%%', 1))
|
call assert_equal('1%', printf('%d%%', 1))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user