diff options
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/coding.c b/src/coding.c index 87b55aecc05..7030a53869a 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -8250,6 +8250,39 @@ decode_coding_object (struct coding_system *coding, | |||
| 8250 | } | 8250 | } |
| 8251 | 8251 | ||
| 8252 | 8252 | ||
| 8253 | /* Encode the text in the range FROM/FROM_BYTE and TO/TO_BYTE in | ||
| 8254 | SRC_OBJECT into DST_OBJECT by coding context CODING. | ||
| 8255 | |||
| 8256 | SRC_OBJECT is a buffer, a string, or Qnil. | ||
| 8257 | |||
| 8258 | If it is a buffer, the text is at point of the buffer. FROM and TO | ||
| 8259 | are positions in the buffer. | ||
| 8260 | |||
| 8261 | If it is a string, the text is at the beginning of the string. | ||
| 8262 | FROM and TO are indices into the string. | ||
| 8263 | |||
| 8264 | If it is nil, the text is at coding->source. FROM and TO are | ||
| 8265 | indices into coding->source. | ||
| 8266 | |||
| 8267 | DST_OBJECT is a buffer, Qt, or Qnil. | ||
| 8268 | |||
| 8269 | If it is a buffer, the encoded text is inserted at point of the | ||
| 8270 | buffer. If the buffer is the same as SRC_OBJECT, the source text | ||
| 8271 | is replaced with the encoded text. | ||
| 8272 | |||
| 8273 | If it is Qt, a string is made from the encoded text, and set in | ||
| 8274 | CODING->dst_object. However, if CODING->raw_destination is non-zero, | ||
| 8275 | the encoded text is instead returned in CODING->destination as a C string, | ||
| 8276 | and the caller is responsible for freeing CODING->destination. This | ||
| 8277 | feature is meant to be used when the caller doesn't need the result as | ||
| 8278 | a Lisp string, and wants to avoid unnecessary consing of large strings. | ||
| 8279 | |||
| 8280 | If it is Qnil, the encoded text is stored at CODING->destination. | ||
| 8281 | The caller must allocate CODING->dst_bytes bytes at | ||
| 8282 | CODING->destination by xmalloc. If the encoded text is longer than | ||
| 8283 | CODING->dst_bytes, CODING->destination is reallocated by xrealloc | ||
| 8284 | (and CODING->dst_bytes is enlarged accordingly). */ | ||
| 8285 | |||
| 8253 | void | 8286 | void |
| 8254 | encode_coding_object (struct coding_system *coding, | 8287 | encode_coding_object (struct coding_system *coding, |
| 8255 | Lisp_Object src_object, | 8288 | Lisp_Object src_object, |
| @@ -8275,11 +8308,14 @@ encode_coding_object (struct coding_system *coding, | |||
| 8275 | 8308 | ||
| 8276 | attrs = CODING_ID_ATTRS (coding->id); | 8309 | attrs = CODING_ID_ATTRS (coding->id); |
| 8277 | 8310 | ||
| 8278 | if (EQ (src_object, dst_object)) | 8311 | bool same_buffer = false; |
| 8312 | if (EQ (src_object, dst_object) && BUFFERP (src_object)) | ||
| 8279 | { | 8313 | { |
| 8280 | struct Lisp_Marker *tail; | 8314 | struct Lisp_Marker *tail; |
| 8281 | 8315 | ||
| 8282 | for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next) | 8316 | same_buffer = true; |
| 8317 | |||
| 8318 | for (tail = BUF_MARKERS (XBUFFER (src_object)); tail; tail = tail->next) | ||
| 8283 | { | 8319 | { |
| 8284 | tail->need_adjustment | 8320 | tail->need_adjustment |
| 8285 | = tail->charpos == (tail->insertion_type ? from : to); | 8321 | = tail->charpos == (tail->insertion_type ? from : to); |
| @@ -8298,7 +8334,7 @@ encode_coding_object (struct coding_system *coding, | |||
| 8298 | else | 8334 | else |
| 8299 | insert_1_both ((char *) coding->source + from, chars, bytes, 0, 0, 0); | 8335 | insert_1_both ((char *) coding->source + from, chars, bytes, 0, 0, 0); |
| 8300 | 8336 | ||
| 8301 | if (EQ (src_object, dst_object)) | 8337 | if (same_buffer) |
| 8302 | { | 8338 | { |
| 8303 | set_buffer_internal (XBUFFER (src_object)); | 8339 | set_buffer_internal (XBUFFER (src_object)); |
| 8304 | saved_pt = PT, saved_pt_byte = PT_BYTE; | 8340 | saved_pt = PT, saved_pt_byte = PT_BYTE; |
| @@ -8329,7 +8365,7 @@ encode_coding_object (struct coding_system *coding, | |||
| 8329 | { | 8365 | { |
| 8330 | code_conversion_save (0, 0); | 8366 | code_conversion_save (0, 0); |
| 8331 | set_buffer_internal (XBUFFER (src_object)); | 8367 | set_buffer_internal (XBUFFER (src_object)); |
| 8332 | if (EQ (src_object, dst_object)) | 8368 | if (same_buffer) |
| 8333 | { | 8369 | { |
| 8334 | saved_pt = PT, saved_pt_byte = PT_BYTE; | 8370 | saved_pt = PT, saved_pt_byte = PT_BYTE; |
| 8335 | coding->src_object = del_range_1 (from, to, 1, 1); | 8371 | coding->src_object = del_range_1 (from, to, 1, 1); |
| @@ -10394,8 +10430,7 @@ encode_file_name (Lisp_Object fname) | |||
| 10394 | cause subtle bugs because the system would silently use a | 10430 | cause subtle bugs because the system would silently use a |
| 10395 | different filename than expected. Perform this check after | 10431 | different filename than expected. Perform this check after |
| 10396 | encoding to not miss NUL bytes introduced through encoding. */ | 10432 | encoding to not miss NUL bytes introduced through encoding. */ |
| 10397 | CHECK_TYPE (memchr (SSDATA (encoded), '\0', SBYTES (encoded)) == NULL, | 10433 | CHECK_STRING_NULL_BYTES (encoded); |
| 10398 | Qfilenamep, fname); | ||
| 10399 | return encoded; | 10434 | return encoded; |
| 10400 | } | 10435 | } |
| 10401 | 10436 | ||