diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-09-27 13:32:06 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-09-27 13:32:06 +0200 |
commit | ce0fac28977af31f1dec411d3535b4de2c3169b3 (patch) | |
tree | bacf6049681872b54c347a76ea5f6f5073dd262f /src | |
parent | 30e8e73506e4522ef4aebf7d525c0e6ffe8805fd (diff) |
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()v8.1.2083
Problem: Multi-byte chars do not work properly with "%.*S" in printf().
Solution: Use mb_ptr2cells(). Daniel Hahler, closes #4989)
Diffstat (limited to 'src')
-rw-r--r-- | src/message.c | 14 | ||||
-rw-r--r-- | src/testdir/test_expr.vim | 3 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/message.c b/src/message.c index b40753415b..dd5f3f519b 100644 --- a/src/message.c +++ b/src/message.c @@ -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; } } diff --git a/src/testdir/test_expr.vim b/src/testdir/test_expr.vim index 365a81344f..253cd49bc9 100644 --- a/src/testdir/test_expr.vim +++ b/src/testdir/test_expr.vim @@ -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 diff --git a/src/version.c b/src/version.c index fa4e956b20..98ddcca846 100644 --- a/src/version.c +++ b/src/version.c @@ -758,6 +758,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2083, +/**/ 2082, /**/ 2081, |