Mercurial > emacs
comparison src/coding.c @ 20803:0fa2183c587d
(ENCODE_ISO_CHARACTER): Pay attention to
CODING_FLAG_ISO_USE_ROMAN and CODING_FLAG_ISO_USE_OLDJIS.
(code_convert_region1): New function.
(Fdecode_coding_region): Call code_convert_region1.
(Fencode_coding_region): Likewise.
(code_convert_string1): New function.
(Fdecode_coding_string): Call code_convert_string1.
(Fencode_coding_string): Likewise.
/
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Fri, 30 Jan 1998 11:05:41 +0000 |
| parents | 13d0a6194de7 |
| children | 068eb408c911 |
comparison
equal
deleted
inserted
replaced
| 20802:8cd0a6343a84 | 20803:0fa2183c587d |
|---|---|
| 1549 >= 0)) \ | 1549 >= 0)) \ |
| 1550 SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ | 1550 SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ |
| 1551 else \ | 1551 else \ |
| 1552 charset_alt = charset; \ | 1552 charset_alt = charset; \ |
| 1553 if (CHARSET_DIMENSION (charset_alt) == 1) \ | 1553 if (CHARSET_DIMENSION (charset_alt) == 1) \ |
| 1554 ENCODE_ISO_CHARACTER_DIMENSION1 (charset_alt, c1); \ | 1554 { \ |
| 1555 if (charset == CHARSET_ASCII \ | |
| 1556 && coding->flags & CODING_FLAG_ISO_USE_ROMAN) \ | |
| 1557 charset_alt = charset_latin_jisx0201; \ | |
| 1558 ENCODE_ISO_CHARACTER_DIMENSION1 (charset_alt, c1); \ | |
| 1559 } \ | |
| 1555 else \ | 1560 else \ |
| 1556 ENCODE_ISO_CHARACTER_DIMENSION2 (charset_alt, c1, c2); \ | 1561 { \ |
| 1562 if (charset == charset_jisx0208 \ | |
| 1563 && coding->flags & CODING_FLAG_ISO_USE_OLDJIS) \ | |
| 1564 charset_alt = charset_jisx0208_1978; \ | |
| 1565 ENCODE_ISO_CHARACTER_DIMENSION2 (charset_alt, c1, c2); \ | |
| 1566 } \ | |
| 1557 if (! COMPOSING_P (coding->composing)) \ | 1567 if (! COMPOSING_P (coding->composing)) \ |
| 1558 coding->consumed_char++; \ | 1568 coding->consumed_char++; \ |
| 1559 } while (0) | 1569 } while (0) |
| 1560 | 1570 |
| 1561 /* Produce designation and invocation codes at a place pointed by DST | 1571 /* Produce designation and invocation codes at a place pointed by DST |
| 1562 to use CHARSET. The element `spec.iso2022' of *CODING is updated. | 1572 to use CHARSET. The element `spec.iso2022' of *CODING is updated. |
| 1563 Return new DST. */ | 1573 Return new DST. */ |
| 1564 | 1574 |
| 4342 return detect_coding_system (XSTRING (string)->data, | 4352 return detect_coding_system (XSTRING (string)->data, |
| 4343 XSTRING (string)->size_byte, | 4353 XSTRING (string)->size_byte, |
| 4344 !NILP (highest)); | 4354 !NILP (highest)); |
| 4345 } | 4355 } |
| 4346 | 4356 |
| 4357 Lisp_Object | |
| 4358 code_convert_region1 (start, end, coding_system, encodep) | |
| 4359 Lisp_Object start, end, coding_system; | |
| 4360 int encodep; | |
| 4361 { | |
| 4362 struct coding_system coding; | |
| 4363 int from, to, len; | |
| 4364 | |
| 4365 CHECK_NUMBER_COERCE_MARKER (start, 0); | |
| 4366 CHECK_NUMBER_COERCE_MARKER (end, 1); | |
| 4367 CHECK_SYMBOL (coding_system, 2); | |
| 4368 | |
| 4369 validate_region (&start, &end); | |
| 4370 from = XFASTINT (start); | |
| 4371 to = XFASTINT (end); | |
| 4372 | |
| 4373 if (NILP (coding_system)) | |
| 4374 return make_number (to - from); | |
| 4375 | |
| 4376 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) | |
| 4377 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data); | |
| 4378 | |
| 4379 coding.mode |= CODING_MODE_LAST_BLOCK; | |
| 4380 len = code_convert_region (from, to, &coding, encodep, 1); | |
| 4381 return make_number (len); | |
| 4382 } | |
| 4383 | |
| 4347 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, | 4384 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, |
| 4348 3, 3, "r\nzCoding system: ", | 4385 3, 3, "r\nzCoding system: ", |
| 4349 "Decode the current region by specified coding system.\n\ | 4386 "Decode the current region by specified coding system.\n\ |
| 4350 When called from a program, takes three arguments:\n\ | 4387 When called from a program, takes three arguments:\n\ |
| 4351 START, END, and CODING-SYSTEM. START and END are buffer positions.\n\ | 4388 START, END, and CODING-SYSTEM. START and END are buffer positions.\n\ |
| 4352 Return length of decoded text.") | 4389 Return length of decoded text.") |
| 4353 (start, end, coding_system) | 4390 (start, end, coding_system) |
| 4354 Lisp_Object start, end, coding_system; | 4391 Lisp_Object start, end, coding_system; |
| 4355 { | 4392 { |
| 4356 struct coding_system coding; | 4393 return code_convert_region1 (start, end, coding_system, 0); |
| 4357 int from, to; | |
| 4358 | |
| 4359 CHECK_NUMBER_COERCE_MARKER (start, 0); | |
| 4360 CHECK_NUMBER_COERCE_MARKER (end, 1); | |
| 4361 CHECK_SYMBOL (coding_system, 2); | |
| 4362 | |
| 4363 validate_region (&start, &end); | |
| 4364 from = XFASTINT (start); | |
| 4365 to = XFASTINT (end); | |
| 4366 | |
| 4367 if (NILP (coding_system)) | |
| 4368 return make_number (to - from); | |
| 4369 | |
| 4370 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) | |
| 4371 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data); | |
| 4372 | |
| 4373 coding.mode |= CODING_MODE_LAST_BLOCK; | |
| 4374 return code_convert_region (from, to, &coding, 0, 1); | |
| 4375 } | 4394 } |
| 4376 | 4395 |
| 4377 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, | 4396 DEFUN ("encode-coding-region", Fencode_coding_region, Sencode_coding_region, |
| 4378 3, 3, "r\nzCoding system: ", | 4397 3, 3, "r\nzCoding system: ", |
| 4379 "Encode the current region by specified coding system.\n\ | 4398 "Encode the current region by specified coding system.\n\ |
| 4381 START, END, and CODING-SYSTEM. START and END are buffer positions.\n\ | 4400 START, END, and CODING-SYSTEM. START and END are buffer positions.\n\ |
| 4382 Return length of encoded text.") | 4401 Return length of encoded text.") |
| 4383 (start, end, coding_system) | 4402 (start, end, coding_system) |
| 4384 Lisp_Object start, end, coding_system; | 4403 Lisp_Object start, end, coding_system; |
| 4385 { | 4404 { |
| 4405 return code_convert_region1 (start, end, coding_system, 1); | |
| 4406 } | |
| 4407 | |
| 4408 Lisp_Object | |
| 4409 code_convert_string1 (string, coding_system, nocopy, encodep) | |
| 4410 Lisp_Object string, coding_system, nocopy; | |
| 4411 int encodep; | |
| 4412 { | |
| 4386 struct coding_system coding; | 4413 struct coding_system coding; |
| 4387 int from, to; | 4414 |
| 4388 | 4415 CHECK_STRING (string, 0); |
| 4389 CHECK_NUMBER_COERCE_MARKER (start, 0); | 4416 CHECK_SYMBOL (coding_system, 1); |
| 4390 CHECK_NUMBER_COERCE_MARKER (end, 1); | |
| 4391 CHECK_SYMBOL (coding_system, 2); | |
| 4392 | |
| 4393 validate_region (&start, &end); | |
| 4394 from = XFASTINT (start); | |
| 4395 to = XFASTINT (end); | |
| 4396 | 4417 |
| 4397 if (NILP (coding_system)) | 4418 if (NILP (coding_system)) |
| 4398 return make_number (to - from); | 4419 return (NILP (nocopy) ? Fcopy_sequence (string) : string); |
| 4399 | 4420 |
| 4400 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) | 4421 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
| 4401 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data); | 4422 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data); |
| 4402 | 4423 |
| 4403 coding.mode |= CODING_MODE_LAST_BLOCK; | 4424 coding.mode |= CODING_MODE_LAST_BLOCK; |
| 4404 return code_convert_region (from, to, &coding, 1, 1); | 4425 return code_convert_string (string, &coding, encodep, !NILP (nocopy)); |
| 4405 } | 4426 } |
| 4406 | 4427 |
| 4407 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, | 4428 DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, |
| 4408 2, 3, 0, | 4429 2, 3, 0, |
| 4409 "Decode STRING which is encoded in CODING-SYSTEM, and return the result.\n\ | 4430 "Decode STRING which is encoded in CODING-SYSTEM, and return the result.\n\ |
| 4410 Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\ | 4431 Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\ |
| 4411 if the decoding operation is trivial.") | 4432 if the decoding operation is trivial.") |
| 4412 (string, coding_system, nocopy) | 4433 (string, coding_system, nocopy) |
| 4413 Lisp_Object string, coding_system, nocopy; | 4434 Lisp_Object string, coding_system, nocopy; |
| 4414 { | 4435 { |
| 4415 struct coding_system coding; | 4436 return code_convert_string1(string, coding_system, nocopy, 0); |
| 4416 | |
| 4417 CHECK_STRING (string, 0); | |
| 4418 CHECK_SYMBOL (coding_system, 1); | |
| 4419 | |
| 4420 if (NILP (coding_system)) | |
| 4421 return (NILP (nocopy) ? Fcopy_sequence (string) : string); | |
| 4422 | |
| 4423 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) | |
| 4424 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data); | |
| 4425 | |
| 4426 coding.mode |= CODING_MODE_LAST_BLOCK; | |
| 4427 return code_convert_string (string, &coding, 0, !NILP (nocopy)); | |
| 4428 } | 4437 } |
| 4429 | 4438 |
| 4430 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, | 4439 DEFUN ("encode-coding-string", Fencode_coding_string, Sencode_coding_string, |
| 4431 2, 3, 0, | 4440 2, 3, 0, |
| 4432 "Encode STRING to CODING-SYSTEM, and return the result.\n\ | 4441 "Encode STRING to CODING-SYSTEM, and return the result.\n\ |
| 4433 Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\ | 4442 Optional arg NOCOPY non-nil means it is ok to return STRING itself\n\ |
| 4434 if the encoding operation is trivial.") | 4443 if the encoding operation is trivial.") |
| 4435 (string, coding_system, nocopy) | 4444 (string, coding_system, nocopy) |
| 4436 Lisp_Object string, coding_system, nocopy; | 4445 Lisp_Object string, coding_system, nocopy; |
| 4437 { | 4446 { |
| 4438 struct coding_system coding; | 4447 return code_convert_string1(string, coding_system, nocopy, 1); |
| 4439 | 4448 } |
| 4440 CHECK_STRING (string, 0); | 4449 |
| 4441 CHECK_SYMBOL (coding_system, 1); | |
| 4442 | |
| 4443 if (NILP (coding_system)) | |
| 4444 return (NILP (nocopy) ? Fcopy_sequence (string) : string); | |
| 4445 | |
| 4446 if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) | |
| 4447 error ("Invalid coding system: %s", XSYMBOL (coding_system)->name->data); | |
| 4448 | |
| 4449 coding.mode |= CODING_MODE_LAST_BLOCK; | |
| 4450 return code_convert_string (string, &coding, 1, !NILP (nocopy)); | |
| 4451 } | |
| 4452 | 4450 |
| 4453 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0, | 4451 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0, |
| 4454 "Decode a JISX0208 character of shift-jis encoding.\n\ | 4452 "Decode a JISX0208 character of shift-jis encoding.\n\ |
| 4455 CODE is the character code in SJIS.\n\ | 4453 CODE is the character code in SJIS.\n\ |
| 4456 Return the corresponding character.") | 4454 Return the corresponding character.") |
