diff options
-rw-r--r-- | src/nvim/strings.c | 13 | ||||
-rw-r--r-- | src/nvim/testdir/test_expr.vim | 5 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c index e2a8108c45..efcd40bb75 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -1001,10 +1001,9 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t - str_arg); } if (fmt_spec == 'S') { - if (min_field_width != 0) { - min_field_width += (strlen(str_arg) - - mb_string2cells((char_u *)str_arg)); - } + size_t base_width = min_field_width; + size_t pad_cell = 0; + if (precision) { char_u *p1; 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; } } - 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; diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 1d7fd3e385..447a519f2c 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -283,6 +283,11 @@ function Test_printf_misc() call assert_equal('🐍', printf('%.2S', '🐍🐍')) 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)) endfunc |