Patch 8.1.2083
Problem:    Multi-byte chars do not work properly with "%.*S" in printf().
Solution:   Use mb_ptr2cells(). Daniel Hahler, closes #4989)
Files:      src/testdir/test_expr.vim, src/message.c


*** ../vim-8.1.2082/src/testdir/test_expr.vim   2019-09-07 19:05:02.337280945 
+0200
--- src/testdir/test_expr.vim   2019-09-27 13:25:52.857968046 +0200
***************
*** 248,253 ****
--- 248,256 ----
    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
  
*** ../vim-8.1.2082/src/message.c       2019-09-21 20:46:14.724275765 +0200
--- src/message.c       2019-09-27 13:28:16.801426049 +0200
***************
*** 4405,4416 ****
                                     - 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);
  
                            str_arg_l = precision = p1 - (char_u *)str_arg;
                        }
                    }
--- 4405,4420 ----
                                     - mb_string2cells((char_u *)str_arg, -1);
                        if (precision)
                        {
!                           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;
                        }
                    }
*** ../vim-8.1.2082/src/version.c       2019-09-27 13:07:59.573833437 +0200
--- src/version.c       2019-09-27 13:31:41.640603797 +0200
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     2083,
  /**/

-- 
DEAD PERSON:  I don't want to go in the cart!
CUSTOMER:     Oh, don't be such a baby.
MORTICIAN:    I can't take him...
DEAD PERSON:  I feel fine!
CUSTOMER:     Oh, do us a favor...
MORTICIAN:    I can't.
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201909271132.x8RBWl1E016360%40masaka.moolenaar.net.

Raspunde prin e-mail lui