diff options
| author | Kenichi Handa | 2004-10-22 13:09:39 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2004-10-22 13:09:39 +0000 |
| commit | 365d14677e0dae7fd34730e9872a5b8fe655f733 (patch) | |
| tree | 4fbc0c695d44b77f7b663da87c50dec56b5ab379 /src | |
| parent | 63ea8ea52fbe8ffbbb06f5a1b5917c63eeaaf47f (diff) | |
| download | emacs-365d14677e0dae7fd34730e9872a5b8fe655f733.tar.gz emacs-365d14677e0dae7fd34730e9872a5b8fe655f733.zip | |
(Ftranslate_region_internal): New function.
(syms_of_editfns): Defsubr it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/src/editfns.c b/src/editfns.c index 2870c59884a..5b129a18a62 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2736,8 +2736,10 @@ Both characters must have the same length of multi-byte form. */) | |||
| 2736 | return Qnil; | 2736 | return Qnil; |
| 2737 | } | 2737 | } |
| 2738 | 2738 | ||
| 2739 | DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0, | 2739 | DEFUN ("translate-region-internal", Ftranslate_region_internal, |
| 2740 | doc: /* From START to END, translate characters according to TABLE. | 2740 | Stranslate_region_internal, 3, 3, 0, |
| 2741 | doc: /* Internal use only. | ||
| 2742 | From START to END, translate characters according to TABLE. | ||
| 2741 | TABLE is a string; the Nth character in it is the mapping | 2743 | TABLE is a string; the Nth character in it is the mapping |
| 2742 | for the character with code N. | 2744 | for the character with code N. |
| 2743 | It returns the number of characters changed. */) | 2745 | It returns the number of characters changed. */) |
| @@ -2750,31 +2752,37 @@ It returns the number of characters changed. */) | |||
| 2750 | register int nc; /* New character. */ | 2752 | register int nc; /* New character. */ |
| 2751 | int cnt; /* Number of changes made. */ | 2753 | int cnt; /* Number of changes made. */ |
| 2752 | int size; /* Size of translate table. */ | 2754 | int size; /* Size of translate table. */ |
| 2753 | int pos, pos_byte; | 2755 | int pos, pos_byte, end_pos; |
| 2754 | int multibyte = !NILP (current_buffer->enable_multibyte_characters); | 2756 | int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
| 2755 | int string_multibyte; | 2757 | int string_multibyte; |
| 2756 | 2758 | ||
| 2757 | validate_region (&start, &end); | 2759 | validate_region (&start, &end); |
| 2758 | CHECK_STRING (table); | 2760 | if (CHAR_TABLE_P (table)) |
| 2759 | 2761 | { | |
| 2760 | if (multibyte != (SCHARS (table) < SBYTES (table))) | 2762 | size = MAX_CHAR; |
| 2761 | table = (multibyte | 2763 | tt = NULL; |
| 2762 | ? string_make_multibyte (table) | 2764 | } |
| 2763 | : string_make_unibyte (table)); | 2765 | else |
| 2764 | string_multibyte = SCHARS (table) < SBYTES (table); | 2766 | { |
| 2767 | CHECK_STRING (table); | ||
| 2765 | 2768 | ||
| 2766 | size = SCHARS (table); | 2769 | if (! multibyte && (SCHARS (table) < SBYTES (table))) |
| 2767 | tt = SDATA (table); | 2770 | table = string_make_unibyte (table); |
| 2771 | string_multibyte = SCHARS (table) < SBYTES (table); | ||
| 2772 | size = SCHARS (table); | ||
| 2773 | tt = SDATA (table); | ||
| 2774 | } | ||
| 2768 | 2775 | ||
| 2769 | pos = XINT (start); | 2776 | pos = XINT (start); |
| 2770 | pos_byte = CHAR_TO_BYTE (pos); | 2777 | pos_byte = CHAR_TO_BYTE (pos); |
| 2778 | end_pos = XINT (end); | ||
| 2771 | modify_region (current_buffer, pos, XINT (end)); | 2779 | modify_region (current_buffer, pos, XINT (end)); |
| 2772 | 2780 | ||
| 2773 | cnt = 0; | 2781 | cnt = 0; |
| 2774 | for (; pos < XINT (end); ) | 2782 | for (; pos < end_pos; ) |
| 2775 | { | 2783 | { |
| 2776 | register unsigned char *p = BYTE_POS_ADDR (pos_byte); | 2784 | register unsigned char *p = BYTE_POS_ADDR (pos_byte); |
| 2777 | unsigned char *str; | 2785 | unsigned char *str, buf[MAX_MULTIBYTE_LENGTH]; |
| 2778 | int len, str_len; | 2786 | int len, str_len; |
| 2779 | int oc; | 2787 | int oc; |
| 2780 | 2788 | ||
| @@ -2784,16 +2792,45 @@ It returns the number of characters changed. */) | |||
| 2784 | oc = *p, len = 1; | 2792 | oc = *p, len = 1; |
| 2785 | if (oc < size) | 2793 | if (oc < size) |
| 2786 | { | 2794 | { |
| 2787 | if (string_multibyte) | 2795 | if (tt) |
| 2788 | { | 2796 | { |
| 2789 | str = tt + string_char_to_byte (table, oc); | 2797 | if (string_multibyte) |
| 2790 | nc = STRING_CHAR_AND_LENGTH (str, MAX_MULTIBYTE_LENGTH, str_len); | 2798 | { |
| 2799 | str = tt + string_char_to_byte (table, oc); | ||
| 2800 | nc = STRING_CHAR_AND_LENGTH (str, MAX_MULTIBYTE_LENGTH, | ||
| 2801 | str_len); | ||
| 2802 | } | ||
| 2803 | else | ||
| 2804 | { | ||
| 2805 | nc = tt[oc]; | ||
| 2806 | if (! ASCII_BYTE_P (nc) && multibyte) | ||
| 2807 | { | ||
| 2808 | str_len = CHAR_STRING (nc, buf); | ||
| 2809 | str = buf; | ||
| 2810 | } | ||
| 2811 | else | ||
| 2812 | { | ||
| 2813 | str_len = 1; | ||
| 2814 | str = tt + oc; | ||
| 2815 | } | ||
| 2816 | } | ||
| 2791 | } | 2817 | } |
| 2792 | else | 2818 | else |
| 2793 | { | 2819 | { |
| 2794 | str = tt + oc; | 2820 | Lisp_Object val; |
| 2795 | nc = tt[oc], str_len = 1; | 2821 | int c; |
| 2822 | |||
| 2823 | nc = oc; | ||
| 2824 | val = CHAR_TABLE_REF (table, oc); | ||
| 2825 | if (INTEGERP (val) | ||
| 2826 | && (c = XINT (val), CHAR_VALID_P (c, 0))) | ||
| 2827 | { | ||
| 2828 | nc = c; | ||
| 2829 | str_len = CHAR_STRING (nc, buf); | ||
| 2830 | str = buf; | ||
| 2831 | } | ||
| 2796 | } | 2832 | } |
| 2833 | |||
| 2797 | if (nc != oc) | 2834 | if (nc != oc) |
| 2798 | { | 2835 | { |
| 2799 | if (len != str_len) | 2836 | if (len != str_len) |
| @@ -4290,7 +4327,7 @@ functions if all the text being accessed has this property. */); | |||
| 4290 | defsubr (&Sinsert_buffer_substring); | 4327 | defsubr (&Sinsert_buffer_substring); |
| 4291 | defsubr (&Scompare_buffer_substrings); | 4328 | defsubr (&Scompare_buffer_substrings); |
| 4292 | defsubr (&Ssubst_char_in_region); | 4329 | defsubr (&Ssubst_char_in_region); |
| 4293 | defsubr (&Stranslate_region); | 4330 | defsubr (&Stranslate_region_internal); |
| 4294 | defsubr (&Sdelete_region); | 4331 | defsubr (&Sdelete_region); |
| 4295 | defsubr (&Sdelete_and_extract_region); | 4332 | defsubr (&Sdelete_and_extract_region); |
| 4296 | defsubr (&Swiden); | 4333 | defsubr (&Swiden); |