diff options
| author | Richard M. Stallman | 1998-03-20 04:59:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-03-20 04:59:15 +0000 |
| commit | 25c9e7fbd77af28b66c505750e962f3465064e51 (patch) | |
| tree | 2139a8f1465976628f6ecf73d3d0ac9a61d1e96b /src | |
| parent | 4d60e093d5519b48980627ec6a07bc22866f01ae (diff) | |
| download | emacs-25c9e7fbd77af28b66c505750e962f3465064e51.tar.gz emacs-25c9e7fbd77af28b66c505750e962f3465064e51.zip | |
(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.c | 34 |
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.") | |||
| 2313 | args[n] = Ffloat (args[n]); | 2313 | args[n] = Ffloat (args[n]); |
| 2314 | #endif | 2314 | #endif |
| 2315 | thissize = 30; | 2315 | thissize = 30; |
| 2316 | if (*format == 'c' && ! SINGLE_BYTE_CHAR_P (XINT (args[n]))) | 2316 | if (*format == 'c' |
| 2317 | && (! SINGLE_BYTE_CHAR_P (XINT (args[n])) | ||
| 2318 | || XINT (args[n]) == 0)) | ||
| 2317 | { | 2319 | { |
| 2318 | if (! multibyte) | 2320 | if (! multibyte) |
| 2319 | { | 2321 | { |
| @@ -2375,6 +2377,7 @@ Use %% to put a single % into the output.") | |||
| 2375 | if (*format == '%') | 2377 | if (*format == '%') |
| 2376 | { | 2378 | { |
| 2377 | int minlen; | 2379 | int minlen; |
| 2380 | int negative = 0; | ||
| 2378 | unsigned char *this_format_start = format; | 2381 | unsigned char *this_format_start = format; |
| 2379 | 2382 | ||
| 2380 | format++; | 2383 | format++; |
| @@ -2382,7 +2385,7 @@ Use %% to put a single % into the output.") | |||
| 2382 | /* Process a numeric arg and skip it. */ | 2385 | /* Process a numeric arg and skip it. */ |
| 2383 | minlen = atoi (format); | 2386 | minlen = atoi (format); |
| 2384 | if (minlen < 0) | 2387 | if (minlen < 0) |
| 2385 | minlen = - minlen; | 2388 | minlen = - minlen, negative = 1; |
| 2386 | 2389 | ||
| 2387 | while ((*format >= '0' && *format <= '9') | 2390 | while ((*format >= '0' && *format <= '9') |
| 2388 | || *format == '-' || *format == ' ' || *format == '.') | 2391 | || *format == '-' || *format == ' ' || *format == '.') |
| @@ -2399,22 +2402,31 @@ Use %% to put a single % into the output.") | |||
| 2399 | 2402 | ||
| 2400 | if (STRINGP (args[n])) | 2403 | if (STRINGP (args[n])) |
| 2401 | { | 2404 | { |
| 2402 | int padding, nbytes, width; | 2405 | int padding, nbytes; |
| 2406 | int width = strwidth (XSTRING (args[n])->data, | ||
| 2407 | XSTRING (args[n])->size_byte); | ||
| 2408 | |||
| 2409 | /* If spec requires it, pad on right with spaces. */ | ||
| 2410 | padding = minlen - width; | ||
| 2411 | if (! negative) | ||
| 2412 | while (padding-- > 0) | ||
| 2413 | { | ||
| 2414 | *p++ = ' '; | ||
| 2415 | nchars++; | ||
| 2416 | } | ||
| 2403 | 2417 | ||
| 2404 | nbytes = copy_text (XSTRING (args[n])->data, p, | 2418 | nbytes = copy_text (XSTRING (args[n])->data, p, |
| 2405 | XSTRING (args[n])->size_byte, | 2419 | XSTRING (args[n])->size_byte, |
| 2406 | STRING_MULTIBYTE (args[n]), multibyte); | 2420 | STRING_MULTIBYTE (args[n]), multibyte); |
| 2407 | width = strwidth (p, nbytes); | ||
| 2408 | p += nbytes; | 2421 | p += nbytes; |
| 2409 | nchars += XSTRING (args[n])->size; | 2422 | nchars += XSTRING (args[n])->size; |
| 2410 | 2423 | ||
| 2411 | /* If spec requires it, pad on right with spaces. */ | 2424 | if (negative) |
| 2412 | padding = minlen - width; | 2425 | while (padding-- > 0) |
| 2413 | while (padding-- > 0) | 2426 | { |
| 2414 | { | 2427 | *p++ = ' '; |
| 2415 | *p++ = ' '; | 2428 | nchars++; |
| 2416 | nchars++; | 2429 | } |
| 2417 | } | ||
| 2418 | } | 2430 | } |
| 2419 | else if (INTEGERP (args[n]) || FLOATP (args[n])) | 2431 | else if (INTEGERP (args[n]) || FLOATP (args[n])) |
| 2420 | { | 2432 | { |