diff options
| author | Kenichi Handa | 2005-02-14 01:04:50 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2005-02-14 01:04:50 +0000 |
| commit | 3bb917bff6b70e242c8aefeb567c4c522cc9d185 (patch) | |
| tree | 1f07c7436f49f76cece1ff32007da75dec5e2b21 /src/coding.c | |
| parent | 1bd70c6e1d8bf8c2a02d68efd0fe8b4fa9bef60d (diff) | |
| download | emacs-3bb917bff6b70e242c8aefeb567c4c522cc9d185.tar.gz emacs-3bb917bff6b70e242c8aefeb567c4c522cc9d185.zip | |
(encode_coding_string): Always return a unibyte string.
If NOCOPY is nonzero and there's no need of encoding, make STR
unibyte directly.
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/coding.c b/src/coding.c index 79e32fbed60..2ab4296381a 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -6361,7 +6361,12 @@ encode_coding_string (str, coding, nocopy) | |||
| 6361 | 6361 | ||
| 6362 | if (SYMBOLP (coding->pre_write_conversion) | 6362 | if (SYMBOLP (coding->pre_write_conversion) |
| 6363 | && !NILP (Ffboundp (coding->pre_write_conversion))) | 6363 | && !NILP (Ffboundp (coding->pre_write_conversion))) |
| 6364 | str = run_pre_post_conversion_on_str (str, coding, 1); | 6364 | { |
| 6365 | str = run_pre_post_conversion_on_str (str, coding, 1); | ||
| 6366 | /* As STR is just newly generated, we don't have to copy it | ||
| 6367 | anymore. */ | ||
| 6368 | nocopy = 1; | ||
| 6369 | } | ||
| 6365 | 6370 | ||
| 6366 | from = 0; | 6371 | from = 0; |
| 6367 | to = SCHARS (str); | 6372 | to = SCHARS (str); |
| @@ -6369,21 +6374,10 @@ encode_coding_string (str, coding, nocopy) | |||
| 6369 | 6374 | ||
| 6370 | /* Encoding routines determine the multibyteness of the source text | 6375 | /* Encoding routines determine the multibyteness of the source text |
| 6371 | by coding->src_multibyte. */ | 6376 | by coding->src_multibyte. */ |
| 6372 | coding->src_multibyte = STRING_MULTIBYTE (str); | 6377 | coding->src_multibyte = SCHARS (str) < SBYTES (str); |
| 6373 | coding->dst_multibyte = 0; | 6378 | coding->dst_multibyte = 0; |
| 6374 | if (! CODING_REQUIRE_ENCODING (coding)) | 6379 | if (! CODING_REQUIRE_ENCODING (coding)) |
| 6375 | { | 6380 | goto no_need_of_encoding; |
| 6376 | coding->consumed = SBYTES (str); | ||
| 6377 | coding->consumed_char = SCHARS (str); | ||
| 6378 | if (STRING_MULTIBYTE (str)) | ||
| 6379 | { | ||
| 6380 | str = Fstring_as_unibyte (str); | ||
| 6381 | nocopy = 1; | ||
| 6382 | } | ||
| 6383 | coding->produced = SBYTES (str); | ||
| 6384 | coding->produced_char = SCHARS (str); | ||
| 6385 | return (nocopy ? str : Fcopy_sequence (str)); | ||
| 6386 | } | ||
| 6387 | 6381 | ||
| 6388 | if (coding->composing != COMPOSITION_DISABLED) | 6382 | if (coding->composing != COMPOSITION_DISABLED) |
| 6389 | coding_save_composition (coding, from, to, str); | 6383 | coding_save_composition (coding, from, to, str); |
| @@ -6399,7 +6393,7 @@ encode_coding_string (str, coding, nocopy) | |||
| 6399 | if (from == to_byte) | 6393 | if (from == to_byte) |
| 6400 | { | 6394 | { |
| 6401 | coding_free_composition_data (coding); | 6395 | coding_free_composition_data (coding); |
| 6402 | return (nocopy ? str : Fcopy_sequence (str)); | 6396 | goto no_need_of_encoding; |
| 6403 | } | 6397 | } |
| 6404 | shrinked_bytes = from + (SBYTES (str) - to_byte); | 6398 | shrinked_bytes = from + (SBYTES (str) - to_byte); |
| 6405 | } | 6399 | } |
| @@ -6444,6 +6438,25 @@ encode_coding_string (str, coding, nocopy) | |||
| 6444 | coding_free_composition_data (coding); | 6438 | coding_free_composition_data (coding); |
| 6445 | 6439 | ||
| 6446 | return newstr; | 6440 | return newstr; |
| 6441 | |||
| 6442 | no_need_of_encoding: | ||
| 6443 | coding->consumed = SBYTES (str); | ||
| 6444 | coding->consumed_char = SCHARS (str); | ||
| 6445 | if (STRING_MULTIBYTE (str)) | ||
| 6446 | { | ||
| 6447 | if (nocopy) | ||
| 6448 | /* We are sure that STR doesn't contain a multibyte | ||
| 6449 | character. */ | ||
| 6450 | STRING_SET_UNIBYTE (str); | ||
| 6451 | else | ||
| 6452 | { | ||
| 6453 | str = Fstring_as_unibyte (str); | ||
| 6454 | nocopy = 1; | ||
| 6455 | } | ||
| 6456 | } | ||
| 6457 | coding->produced = SBYTES (str); | ||
| 6458 | coding->produced_char = SCHARS (str); | ||
| 6459 | return (nocopy ? str : Fcopy_sequence (str)); | ||
| 6447 | } | 6460 | } |
| 6448 | 6461 | ||
| 6449 | 6462 | ||