Mercurial > emacs
comparison src/coding.c @ 60031:8d84cdf36525
(encode_coding_string): Always return a unibyte string.
If NOCOPY is nonzero and there's no need of encoding, make STR
unibyte directly.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Mon, 14 Feb 2005 01:01:50 +0000 |
| parents | a691d3c9971a |
| children | 4b80e9c28e8f 9684495d72bc |
comparison
equal
deleted
inserted
replaced
| 60030:e41b38ec1a82 | 60031:8d84cdf36525 |
|---|---|
| 6359 Lisp_Object newstr; | 6359 Lisp_Object newstr; |
| 6360 int consumed, consumed_char, produced, produced_char; | 6360 int consumed, consumed_char, produced, produced_char; |
| 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); |
| 6368 to_byte = SBYTES (str); | 6373 to_byte = SBYTES (str); |
| 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); |
| 6390 | 6384 |
| 6391 /* Try to skip the heading and tailing ASCIIs. We can't skip them | 6385 /* Try to skip the heading and tailing ASCIIs. We can't skip them |
| 6397 SHRINK_CONVERSION_REGION (&from, &to_byte, coding, SDATA (str), | 6391 SHRINK_CONVERSION_REGION (&from, &to_byte, coding, SDATA (str), |
| 6398 1); | 6392 1); |
| 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 } |
| 6406 | 6400 |
| 6407 len = encoding_buffer_size (coding, to_byte - from); | 6401 len = encoding_buffer_size (coding, to_byte - from); |
| 6442 | 6436 |
| 6443 free_conversion_buffer (&buf); | 6437 free_conversion_buffer (&buf); |
| 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 |
| 6450 #ifdef emacs | 6463 #ifdef emacs |
| 6451 /*** 8. Emacs Lisp library functions ***/ | 6464 /*** 8. Emacs Lisp library functions ***/ |
