Blob Blame History Raw
To: vim_dev@googlegroups.com
Subject: Patch 7.3.713
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.713
Problem:    printf() can only align to bytes, not characters.
Solution:   Add the "S" item. (Christian Brabandt)
Files:	    runtime/doc/eval.txt, src/message.c


*** ../vim-7.3.712/runtime/doc/eval.txt	2012-10-21 00:44:59.000000000 +0200
--- runtime/doc/eval.txt	2012-11-14 18:00:40.000000000 +0100
***************
*** 4427,4432 ****
--- 4451,4457 ----
  
  		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
***************
*** 4541,4546 ****
--- 4566,4575 ----
  		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 
*** ../vim-7.3.712/src/message.c	2012-03-28 16:49:25.000000000 +0200
--- src/message.c	2012-11-14 17:58:25.000000000 +0100
***************
*** 4290,4295 ****
--- 4290,4296 ----
  	    case '%':
  	    case 'c':
  	    case 's':
+ 	    case 'S':
  		length_modifier = '\0';
  		str_arg_l = 1;
  		switch (fmt_spec)
***************
*** 4318,4323 ****
--- 4319,4325 ----
  		    }
  
  		case 's':
+ 		case 'S':
  		    str_arg =
  #ifndef HAVE_STDARG_H
  				(char *)get_a_arg(arg_idx);
***************
*** 4354,4359 ****
--- 4356,4379 ----
  			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:
*** ../vim-7.3.712/src/version.c	2012-10-23 05:35:30.000000000 +0200
--- src/version.c	2012-11-14 17:54:12.000000000 +0100
***************
*** 727,728 ****
--- 727,730 ----
  {   /* Add new patch number below this line */
+ /**/
+     713,
  /**/

-- 
In many of the more relaxed civilizations on the Outer Eastern Rim of the
Galaxy, "The Hitchhiker's Guide to the Galaxy" has already supplanted the
great "Encyclopedia Galactica" as the standard repository of all knowledge
and wisdom, for though it has many omissions and contains much that is
apocryphal, or at least wildly inaccurate, it scores over the older, more
pedestrian work in two important respects.
First, it is slightly cheaper; and second, it has the words "DON'T PANIC"
inscribed in large friendly letters on its cover.
		-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// Bram Moolenaar -- Bram@Moolenaar.net -- 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    ///