summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1998-03-20 04:59:15 +0000
committerRichard M. Stallman <rms@gnu.org>1998-03-20 04:59:15 +0000
commit25c9e7fbd77af28b66c505750e962f3465064e51 (patch)
tree2139a8f1465976628f6ecf73d3d0ac9a61d1e96b /src
parent4d60e093d5519b48980627ec6a07bc22866f01ae (diff)
downloademacs-25c9e7fbd77af28b66c505750e962f3465064e51.tar.gz
(Fformat): Handle padding before or after, for %s etc.
Treat 0 like a multibyte char in %c.
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/editfns.c b/src/editfns.c
index f25b6aa8f34..d5b204e6923 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2313,7 +2313,9 @@ Use %% to put a single % into the output.")
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 @@ Use %% to put a single % into the output.")
if (*format == '%')
{
int minlen;
+ int negative = 0;
unsigned char *this_format_start = format;
format++;
@@ -2382,7 +2385,7 @@ Use %% to put a single % into the output.")
/* 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 @@ Use %% to put a single % into the output.")
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]))
{