updated for version 7.3.713 v7.3.713
authorBram Moolenaar <Bram@vim.org>
Wed, 14 Nov 2012 17:10:56 +0000 (18:10 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 14 Nov 2012 17:10:56 +0000 (18:10 +0100)
Problem:    printf() can only align to bytes, not characters.
Solution:   Add the "S" item. (Christian Brabandt)

runtime/doc/eval.txt
src/message.c
src/version.c

index 3afc3d0f7ad64e3863db384931a28548611a289c..f105cf104c7c742a27905d5e66ccf2d26f6c8df0 100644 (file)
@@ -4451,6 +4451,7 @@ printf({fmt}, {expr1} ...)                                *printf()*
 
                Often used items are:
                  %s    string
+                 %6S   string right-aligned in 6 display cells
                  %6s   string right-aligned in 6 bytes
                  %.9s  string truncated to 9 bytes
                  %c    single byte
@@ -4565,6 +4566,10 @@ printf({fmt}, {expr1} ...)                               *printf()*
                s       The text of the String argument is used.  If a
                        precision is specified, no more bytes than the number
                        specified are used.
+               S       The text of the String argument is used.  If a
+                       precision is specified, no more display cells than the
+                       number specified are used.  Without the |+multi_byte|
+                       feature works just like 's'.
 
                                                        *printf-f* *E807*
                f       The Float argument is converted into a string of the 
index b9cc93fa1c8fc9b04096b517be6b730fb924748a..f5d17146a9d5cb70512de883dee70d300d05b4e2 100644 (file)
@@ -4290,6 +4290,7 @@ vim_snprintf(str, str_m, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
            case '%':
            case 'c':
            case 's':
+           case 'S':
                length_modifier = '\0';
                str_arg_l = 1;
                switch (fmt_spec)
@@ -4318,6 +4319,7 @@ vim_snprintf(str, str_m, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
                    }
 
                case 's':
+               case 'S':
                    str_arg =
 #ifndef HAVE_STDARG_H
                                (char *)get_a_arg(arg_idx);
@@ -4354,6 +4356,24 @@ vim_snprintf(str, str_m, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
                        str_arg_l = (q == NULL) ? precision
                                                      : (size_t)(q - str_arg);
                    }
+#ifdef FEAT_MBYTE
+                   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 = (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;
+                       }
+                   }
+#endif
                    break;
 
                default:
index 87d0e620c224c41c94f080cbf027e8195b4fcfa7..3c9bae78095323db36ea79fef32eb6235955c96c 100644 (file)
@@ -725,6 +725,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    713,
 /**/
     712,
 /**/