changeset 21225:47e189a470d2

(Fformat): Handle padding before or after, for %s etc. Treat 0 like a multibyte char in %c.
author Richard M. Stallman <rms@gnu.org>
date Fri, 20 Mar 1998 04:59:15 +0000
parents 1581abe1a67e
children c8d0df2cbd3d
files src/editfns.c
diffstat 1 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/editfns.c	Fri Mar 20 04:41:13 1998 +0000
+++ b/src/editfns.c	Fri Mar 20 04:59:15 1998 +0000
@@ -2313,7 +2313,9 @@
 	      args[n] = Ffloat (args[n]);
 #endif
 	    thissize = 30;	
-	    if (*format == 'c' && ! SINGLE_BYTE_CHAR_P (XINT (args[n])))
+	    if (*format == 'c'
+		&& (! SINGLE_BYTE_CHAR_P (XINT (args[n]))
+		    || XINT (args[n]) == 0))
 	      {
 		if (! multibyte)
 		  {
@@ -2375,6 +2377,7 @@
       if (*format == '%')
 	{
 	  int minlen;
+	  int negative = 0;
 	  unsigned char *this_format_start = format;
 
 	  format++;
@@ -2382,7 +2385,7 @@
 	  /* Process a numeric arg and skip it.  */
 	  minlen = atoi (format);
 	  if (minlen < 0)
-	    minlen = - minlen;
+	    minlen = - minlen, negative = 1;
 
 	  while ((*format >= '0' && *format <= '9')
 		 || *format == '-' || *format == ' ' || *format == '.')
@@ -2399,22 +2402,31 @@
 
 	  if (STRINGP (args[n]))
 	    {
-	      int padding, nbytes, width;
+	      int padding, nbytes;
+	      int width = strwidth (XSTRING (args[n])->data,
+				    XSTRING (args[n])->size_byte);
+
+	      /* If spec requires it, pad on right with spaces.  */
+	      padding = minlen - width;
+	      if (! negative)
+		while (padding-- > 0)
+		  {
+		    *p++ = ' ';
+		    nchars++;
+		  }
 
 	      nbytes = copy_text (XSTRING (args[n])->data, p,
 				  XSTRING (args[n])->size_byte,
 				  STRING_MULTIBYTE (args[n]), multibyte);
-	      width = strwidth (p, nbytes);
 	      p += nbytes;
 	      nchars += XSTRING (args[n])->size;
 
-	      /* If spec requires it, pad on right with spaces.  */
-	      padding = minlen - width;
-	      while (padding-- > 0)
-		{
-		  *p++ = ' ';
-		  nchars++;
-		}
+	      if (negative)
+		while (padding-- > 0)
+		  {
+		    *p++ = ' ';
+		    nchars++;
+		  }
 	    }
 	  else if (INTEGERP (args[n]) || FLOATP (args[n]))
 	    {