Patch 8.2.3630
Problem:    Printf() with %S does not handle multi-byte correctly.
Solution:   Count cells instead of bytes. (closes #9169, closes #7486)
Files:      src/strings.c, src/testdir/test_expr.vim


*** ../vim-8.2.3629/src/strings.c       2021-09-01 13:31:47.627129937 +0100
--- src/strings.c       2021-11-20 19:36:20.702823402 +0000
***************
*** 2137,2150 ****
                        char *q = memchr(str_arg, '\0',
                                  precision <= (size_t)0x7fffffffL ? precision
                                                       : (size_t)0x7fffffffL);
                        str_arg_l = (q == NULL) ? precision
                                                      : (size_t)(q - str_arg);
                    }
                    if (fmt_spec == 'S')
                    {
!                       if (min_field_width != 0)
!                           min_field_width += STRLEN(str_arg)
!                                    - mb_string2cells((char_u *)str_arg, -1);
                        if (precision)
                        {
                            char_u  *p1;
--- 2137,2151 ----
                        char *q = memchr(str_arg, '\0',
                                  precision <= (size_t)0x7fffffffL ? precision
                                                       : (size_t)0x7fffffffL);
+ 
                        str_arg_l = (q == NULL) ? precision
                                                      : (size_t)(q - str_arg);
                    }
                    if (fmt_spec == 'S')
                    {
!                       size_t base_width = min_field_width;
!                       size_t pad_cell = 0;
! 
                        if (precision)
                        {
                            char_u  *p1;
***************
*** 2157,2164 ****
                                if (i > precision)
                                    break;
                            }
!                           str_arg_l = precision = p1 - (char_u *)str_arg;
                        }
                    }
                    break;
  
--- 2158,2169 ----
                                if (i > precision)
                                    break;
                            }
!                           pad_cell = min_field_width - precision;
!                           base_width = str_arg_l = precision =
!                                                       p1 - (char_u *)str_arg;
                        }
+                       if (min_field_width != 0)
+                           min_field_width = base_width + pad_cell;
                    }
                    break;
  
*** ../vim-8.2.3629/src/testdir/test_expr.vim   2021-08-28 11:49:21.957091792 
+0100
--- src/testdir/test_expr.vim   2021-11-20 19:27:36.092019974 +0000
***************
*** 297,302 ****
--- 297,307 ----
    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
  
*** ../vim-8.2.3629/src/version.c       2021-11-20 19:13:35.945146370 +0000
--- src/version.c       2021-11-20 19:36:38.078773395 +0000
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     3630,
  /**/

-- 
If "R" is Reverse, how come "D" is FORWARD?

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/20211120193904.51E741C044E%40moolenaar.net.

Raspunde prin e-mail lui