2736 |
return Qnil; |
return Qnil; |
2737 |
} |
} |
2738 |
|
|
2739 |
DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0, |
DEFUN ("translate-region-internal", Ftranslate_region_internal, |
2740 |
doc: /* From START to END, translate characters according to TABLE. |
Stranslate_region_internal, 3, 3, 0, |
2741 |
|
doc: /* Internal use only. |
2742 |
|
From START to END, translate characters according to TABLE. |
2743 |
TABLE is a string; the Nth character in it is the mapping |
TABLE is a string; the Nth character in it is the mapping |
2744 |
for the character with code N. |
for the character with code N. |
2745 |
It returns the number of characters changed. */) |
It returns the number of characters changed. */) |
2752 |
register int nc; /* New character. */ |
register int nc; /* New character. */ |
2753 |
int cnt; /* Number of changes made. */ |
int cnt; /* Number of changes made. */ |
2754 |
int size; /* Size of translate table. */ |
int size; /* Size of translate table. */ |
2755 |
int pos, pos_byte; |
int pos, pos_byte, end_pos; |
2756 |
int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
2757 |
int string_multibyte; |
int string_multibyte; |
2758 |
|
|
2759 |
validate_region (&start, &end); |
validate_region (&start, &end); |
2760 |
CHECK_STRING (table); |
if (CHAR_TABLE_P (table)) |
2761 |
|
{ |
2762 |
if (multibyte != (SCHARS (table) < SBYTES (table))) |
size = MAX_CHAR; |
2763 |
table = (multibyte |
tt = NULL; |
2764 |
? string_make_multibyte (table) |
} |
2765 |
: string_make_unibyte (table)); |
else |
2766 |
string_multibyte = SCHARS (table) < SBYTES (table); |
{ |
2767 |
|
CHECK_STRING (table); |
2768 |
|
|
2769 |
size = SCHARS (table); |
if (! multibyte && (SCHARS (table) < SBYTES (table))) |
2770 |
tt = SDATA (table); |
table = string_make_unibyte (table); |
2771 |
|
string_multibyte = SCHARS (table) < SBYTES (table); |
2772 |
|
size = SCHARS (table); |
2773 |
|
tt = SDATA (table); |
2774 |
|
} |
2775 |
|
|
2776 |
pos = XINT (start); |
pos = XINT (start); |
2777 |
pos_byte = CHAR_TO_BYTE (pos); |
pos_byte = CHAR_TO_BYTE (pos); |
2778 |
|
end_pos = XINT (end); |
2779 |
modify_region (current_buffer, pos, XINT (end)); |
modify_region (current_buffer, pos, XINT (end)); |
2780 |
|
|
2781 |
cnt = 0; |
cnt = 0; |
2782 |
for (; pos < XINT (end); ) |
for (; pos < end_pos; ) |
2783 |
{ |
{ |
2784 |
register unsigned char *p = BYTE_POS_ADDR (pos_byte); |
register unsigned char *p = BYTE_POS_ADDR (pos_byte); |
2785 |
unsigned char *str; |
unsigned char *str, buf[MAX_MULTIBYTE_LENGTH]; |
2786 |
int len, str_len; |
int len, str_len; |
2787 |
int oc; |
int oc; |
2788 |
|
|
2792 |
oc = *p, len = 1; |
oc = *p, len = 1; |
2793 |
if (oc < size) |
if (oc < size) |
2794 |
{ |
{ |
2795 |
if (string_multibyte) |
if (tt) |
2796 |
{ |
{ |
2797 |
str = tt + string_char_to_byte (table, oc); |
if (string_multibyte) |
2798 |
nc = STRING_CHAR_AND_LENGTH (str, MAX_MULTIBYTE_LENGTH, str_len); |
{ |
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 |
|
} |
2817 |
} |
} |
2818 |
else |
else |
2819 |
{ |
{ |
2820 |
str = tt + oc; |
Lisp_Object val; |
2821 |
nc = tt[oc], str_len = 1; |
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 |
|
} |
2832 |
} |
} |
2833 |
|
|
2834 |
if (nc != oc) |
if (nc != oc) |
2835 |
{ |
{ |
2836 |
if (len != str_len) |
if (len != str_len) |
4327 |
defsubr (&Sinsert_buffer_substring); |
defsubr (&Sinsert_buffer_substring); |
4328 |
defsubr (&Scompare_buffer_substrings); |
defsubr (&Scompare_buffer_substrings); |
4329 |
defsubr (&Ssubst_char_in_region); |
defsubr (&Ssubst_char_in_region); |
4330 |
defsubr (&Stranslate_region); |
defsubr (&Stranslate_region_internal); |
4331 |
defsubr (&Sdelete_region); |
defsubr (&Sdelete_region); |
4332 |
defsubr (&Sdelete_and_extract_region); |
defsubr (&Sdelete_and_extract_region); |
4333 |
defsubr (&Swiden); |
defsubr (&Swiden); |