Patch 8.2.3663
Problem:    Using %S in printf() does not work correctly.
Solution:   Fix the problem and add more tests. (closes #9208)
Files:      src/strings.c, src/testdir/test_expr.vim


*** ../vim-8.2.3662/src/strings.c       2021-11-20 19:38:22.158489234 +0000
--- src/strings.c       2021-11-24 15:30:56.595899392 +0000
***************
*** 2143,2169 ****
                    }
                    if (fmt_spec == 'S')
                    {
!                       size_t base_width = min_field_width;
!                       size_t pad_cell = 0;
  
!                       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;
!                           }
!                           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;
  
--- 2143,2164 ----
                    }
                    if (fmt_spec == 'S')
                    {
!                       char_u  *p1;
!                       size_t  i;
!                       int     cell;
  
!                       for (i = 0, p1 = (char_u *)str_arg; *p1;
                                                          p1 += mb_ptr2len(p1))
!                       {
!                           cell = mb_ptr2cells(p1);
!                           if (precision_specified && i + cell > precision)
!                               break;
!                           i += cell;
                        }
+ 
+                       str_arg_l = p1 - (char_u *)str_arg;
                        if (min_field_width != 0)
!                           min_field_width += str_arg_l - i;
                    }
                    break;
  
*** ../vim-8.2.3662/src/testdir/test_expr.vim   2021-11-20 19:38:22.158489234 
+0000
--- src/testdir/test_expr.vim   2021-11-24 15:27:46.932088107 +0000
***************
*** 302,307 ****
--- 302,367 ----
    call assert_equal('[あいうえお]', printf('[%10.10S]', 'あいうえお'))
    call assert_equal('[あいうえお]', printf('[%10.12S]', 'あいうえお'))
  
+   call assert_equal('あいう', printf('%S', 'あいう'))
+   call assert_equal('あいう', printf('%#S', 'あいう'))
+ 
+   call assert_equal('あb', printf('%2S', 'あb'))
+   call assert_equal('あb', printf('%.4S', 'あb'))
+   call assert_equal('あ', printf('%.2S', 'あb'))
+   call assert_equal(' あb', printf('%4S', 'あb'))
+   call assert_equal('0あb', printf('%04S', 'あb'))
+   call assert_equal('あb ', printf('%-4S', 'あb'))
+   call assert_equal('あ  ', printf('%-4.2S', 'あb'))
+ 
+   call assert_equal('aい', printf('%2S', 'aい'))
+   call assert_equal('aい', printf('%.4S', 'aい'))
+   call assert_equal('a', printf('%.2S', 'aい'))
+   call assert_equal(' aい', printf('%4S', 'aい'))
+   call assert_equal('0aい', printf('%04S', 'aい'))
+   call assert_equal('aい ', printf('%-4S', 'aい'))
+   call assert_equal('a   ', printf('%-4.2S', 'aい'))
+ 
+   call assert_equal('[あいう]', printf('[%05S]', 'あいう'))
+   call assert_equal('[あいう]', printf('[%06S]', 'あいう'))
+   call assert_equal('[0あいう]', printf('[%07S]', 'あいう'))
+ 
+   call assert_equal('[あiう]', printf('[%05S]', 'あiう'))
+   call assert_equal('[0あiう]', printf('[%06S]', 'あiう'))
+   call assert_equal('[00あiう]', printf('[%07S]', 'あiう'))
+ 
+   call assert_equal('[0あい]', printf('[%05.4S]', 'あいう'))
+   call assert_equal('[00あい]', printf('[%06.4S]', 'あいう'))
+   call assert_equal('[000あい]', printf('[%07.4S]', 'あいう'))
+ 
+   call assert_equal('[00あi]', printf('[%05.4S]', 'あiう'))
+   call assert_equal('[000あi]', printf('[%06.4S]', 'あiう'))
+   call assert_equal('[0000あi]', printf('[%07.4S]', 'あiう'))
+ 
+   call assert_equal('[0あい]', printf('[%05.5S]', 'あいう'))
+   call assert_equal('[00あい]', printf('[%06.5S]', 'あいう'))
+   call assert_equal('[000あい]', printf('[%07.5S]', 'あいう'))
+ 
+   call assert_equal('[あiう]', printf('[%05.5S]', 'あiう'))
+   call assert_equal('[0あiう]', printf('[%06.5S]', 'あiう'))
+   call assert_equal('[00あiう]', printf('[%07.5S]', 'あiう'))
+ 
+   call assert_equal('[0000000000]', printf('[%010.0S]', 'あいう'))
+   call assert_equal('[0000000000]', printf('[%010.1S]', 'あいう'))
+   call assert_equal('[00000000あ]', printf('[%010.2S]', 'あいう'))
+   call assert_equal('[00000000あ]', printf('[%010.3S]', 'あいう'))
+   call assert_equal('[000000あい]', printf('[%010.4S]', 'あいう'))
+   call assert_equal('[000000あい]', printf('[%010.5S]', 'あいう'))
+   call assert_equal('[0000あいう]', printf('[%010.6S]', 'あいう'))
+   call assert_equal('[0000あいう]', printf('[%010.7S]', 'あいう'))
+ 
+   call assert_equal('[0000000000]', printf('[%010.1S]', 'あiう'))
+   call assert_equal('[00000000あ]', printf('[%010.2S]', 'あiう'))
+   call assert_equal('[0000000あi]', printf('[%010.3S]', 'あiう'))
+   call assert_equal('[0000000あi]', printf('[%010.4S]', 'あiう'))
+   call assert_equal('[00000あiう]', printf('[%010.5S]', 'あiう'))
+   call assert_equal('[00000あiう]', printf('[%010.6S]', 'あiう'))
+   call assert_equal('[00000あiう]', printf('[%010.7S]', 'あiう'))
+ 
    call assert_equal('1%', printf('%d%%', 1))
  endfunc
  
*** ../vim-8.2.3662/src/version.c       2021-11-24 15:13:21.752710735 +0000
--- src/version.c       2021-11-24 15:32:34.479798889 +0000
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     3663,
  /**/

-- 
Close your shells, or I'll kill -9 you
Tomorrow I'll quota you
Remember the disks'll always be full
And then while I'm away
I'll write ~ everyday
And I'll send-pr all my buggings to you.
    [ CVS log "Beatles style" for FreeBSD ports/INDEX, Satoshi Asami ]

 /// 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/20211124160109.A30811C03A0%40moolenaar.net.

Raspunde prin e-mail lui