diff options
| author | Kenichi Handa | 1998-07-06 01:47:34 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1998-07-06 01:47:34 +0000 |
| commit | 8f2917e4dc59d1394a34e49371e19e29fac9966d (patch) | |
| tree | 2f29d63892b5d1c3a2c2328162de97e50563b7b1 /src | |
| parent | 2df42e09659b920a3777f61653d7386a84b2b04e (diff) | |
| download | emacs-8f2917e4dc59d1394a34e49371e19e29fac9966d.tar.gz emacs-8f2917e4dc59d1394a34e49371e19e29fac9966d.zip | |
(Fformat): Pay attention to the byte combining problem.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/editfns.c b/src/editfns.c index 40f0a51d454..258ce2b2e79 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2320,6 +2320,11 @@ Use %% to put a single % into the output.") | |||
| 2320 | /* Nonzero if the output should be a multibyte string, | 2320 | /* Nonzero if the output should be a multibyte string, |
| 2321 | which is true if any of the inputs is one. */ | 2321 | which is true if any of the inputs is one. */ |
| 2322 | int multibyte = 0; | 2322 | int multibyte = 0; |
| 2323 | /* When we make a multibyte string, we must pay attention to the | ||
| 2324 | byte combining problem, i.e., a byte may be combined with a | ||
| 2325 | multibyte charcter of the previous string. This flag tells if we | ||
| 2326 | must consider such a situation or not. */ | ||
| 2327 | int maybe_combine_byte; | ||
| 2323 | unsigned char *this_format; | 2328 | unsigned char *this_format; |
| 2324 | int longest_format; | 2329 | int longest_format; |
| 2325 | Lisp_Object val; | 2330 | Lisp_Object val; |
| @@ -2476,6 +2481,7 @@ Use %% to put a single % into the output.") | |||
| 2476 | 2481 | ||
| 2477 | /* Scan the format and store result in BUF. */ | 2482 | /* Scan the format and store result in BUF. */ |
| 2478 | format = XSTRING (args[0])->data; | 2483 | format = XSTRING (args[0])->data; |
| 2484 | maybe_combine_byte = 0; | ||
| 2479 | while (format != end) | 2485 | while (format != end) |
| 2480 | { | 2486 | { |
| 2481 | if (*format == '%') | 2487 | if (*format == '%') |
| @@ -2519,6 +2525,12 @@ Use %% to put a single % into the output.") | |||
| 2519 | nchars++; | 2525 | nchars++; |
| 2520 | } | 2526 | } |
| 2521 | 2527 | ||
| 2528 | if (p > buf | ||
| 2529 | && multibyte | ||
| 2530 | && *((unsigned char *) p - 1) >= 0x80 | ||
| 2531 | && STRING_MULTIBYTE (args[n]) | ||
| 2532 | && XSTRING (args[n])->data[0] >= 0xA0) | ||
| 2533 | maybe_combine_byte = 1; | ||
| 2522 | nbytes = copy_text (XSTRING (args[n])->data, p, | 2534 | nbytes = copy_text (XSTRING (args[n])->data, p, |
| 2523 | STRING_BYTES (XSTRING (args[n])), | 2535 | STRING_BYTES (XSTRING (args[n])), |
| 2524 | STRING_MULTIBYTE (args[n]), multibyte); | 2536 | STRING_MULTIBYTE (args[n]), multibyte); |
| @@ -2545,6 +2557,11 @@ Use %% to put a single % into the output.") | |||
| 2545 | else | 2557 | else |
| 2546 | sprintf (p, this_format, XFLOAT (args[n])->data); | 2558 | sprintf (p, this_format, XFLOAT (args[n])->data); |
| 2547 | 2559 | ||
| 2560 | if (p > buf | ||
| 2561 | && multibyte | ||
| 2562 | && *((unsigned char *) p - 1) >= 0x80 | ||
| 2563 | && *((unsigned char *) p) >= 0xA0) | ||
| 2564 | maybe_combine_byte = 1; | ||
| 2548 | this_nchars = strlen (p); | 2565 | this_nchars = strlen (p); |
| 2549 | p += this_nchars; | 2566 | p += this_nchars; |
| 2550 | nchars += this_nchars; | 2567 | nchars += this_nchars; |
| @@ -2553,6 +2570,11 @@ Use %% to put a single % into the output.") | |||
| 2553 | else if (STRING_MULTIBYTE (args[0])) | 2570 | else if (STRING_MULTIBYTE (args[0])) |
| 2554 | { | 2571 | { |
| 2555 | /* Copy a whole multibyte character. */ | 2572 | /* Copy a whole multibyte character. */ |
| 2573 | if (p > buf | ||
| 2574 | && multibyte | ||
| 2575 | && *((unsigned char *) p - 1) >= 0x80 | ||
| 2576 | && *format >= 0xA0) | ||
| 2577 | maybe_combine_byte = 1; | ||
| 2556 | *p++ = *format++; | 2578 | *p++ = *format++; |
| 2557 | while (! CHAR_HEAD_P (*format)) *p++ = *format++; | 2579 | while (! CHAR_HEAD_P (*format)) *p++ = *format++; |
| 2558 | nchars++; | 2580 | nchars++; |
| @@ -2570,6 +2592,8 @@ Use %% to put a single % into the output.") | |||
| 2570 | *p++ = *format++, nchars++; | 2592 | *p++ = *format++, nchars++; |
| 2571 | } | 2593 | } |
| 2572 | 2594 | ||
| 2595 | if (maybe_combine_byte) | ||
| 2596 | nchars = multibyte_chars_in_text (buf, p - buf); | ||
| 2573 | val = make_specified_string (buf, nchars, p - buf, multibyte); | 2597 | val = make_specified_string (buf, nchars, p - buf, multibyte); |
| 2574 | 2598 | ||
| 2575 | /* If we allocated BUF with malloc, free it too. */ | 2599 | /* If we allocated BUF with malloc, free it too. */ |