aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1998-01-18 04:53:32 +0000
committerKarl Heuer1998-01-18 04:53:32 +0000
commitf8bd51c41a7d2429cd5586a38fdbc579e9d7fe3f (patch)
tree18e8be1972cdf309d9e34a88cbbc29137778a865 /src
parent974a6ff52fadfb760a2c291de5137ea3f9d64844 (diff)
downloademacs-f8bd51c41a7d2429cd5586a38fdbc579e9d7fe3f.tar.gz
emacs-f8bd51c41a7d2429cd5586a38fdbc579e9d7fe3f.zip
(compile_pattern_1): If representation of STRING
does not fit MULTIBYTE, convert its contents. (fast_c_string_match_ignore_case): Pass 0 to compile_pattern as MULTIBYTE. (search_buffer): If representation of STRING does not fit MULTIBYTE, convert its contents.
Diffstat (limited to 'src')
-rw-r--r--src/search.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/src/search.c b/src/search.c
index 1a850713aae..176de17df8d 100644
--- a/src/search.c
+++ b/src/search.c
@@ -122,9 +122,42 @@ compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
122 int posix; 122 int posix;
123 int multibyte; 123 int multibyte;
124{ 124{
125 char *raw_pattern;
126 int raw_pattern_size;
125 char *val; 127 char *val;
126 reg_syntax_t old; 128 reg_syntax_t old;
127 129
130 /* MULTIBYTE says whether the text to be searched is multibyte.
131 We must convert PATTERN to match that, or we will not really
132 find things right. */
133
134 if (multibyte == STRING_MULTIBYTE (pattern))
135 {
136 raw_pattern = (char *) XSTRING (pattern)->data;
137 raw_pattern_size = XSTRING (pattern)->size_byte;
138 }
139 else if (multibyte)
140 {
141 raw_pattern_size = count_size_as_multibyte (XSTRING (pattern)->data,
142 XSTRING (pattern)->size);
143 raw_pattern = (char *) alloca (raw_pattern_size + 1);
144 copy_text (XSTRING (pattern)->data, raw_pattern,
145 XSTRING (pattern)->size, 0, 1);
146 }
147 else
148 {
149 /* Converting multibyte to single-byte.
150
151 ??? Perhaps this conversion should be done in a special way
152 by subtracting nonascii-insert-offset from each non-ASCII char,
153 so that only the multibyte chars which really correspond to
154 the chosen single-byte character set can possibly match. */
155 raw_pattern_size = XSTRING (pattern)->size;
156 raw_pattern = (char *) alloca (raw_pattern_size + 1);
157 copy_text (XSTRING (pattern)->data, raw_pattern,
158 XSTRING (pattern)->size, 1, 0);
159 }
160
128 cp->regexp = Qnil; 161 cp->regexp = Qnil;
129 cp->buf.translate = translate; 162 cp->buf.translate = translate;
130 cp->posix = posix; 163 cp->posix = posix;
@@ -132,8 +165,7 @@ compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
132 BLOCK_INPUT; 165 BLOCK_INPUT;
133 old = re_set_syntax (RE_SYNTAX_EMACS 166 old = re_set_syntax (RE_SYNTAX_EMACS
134 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); 167 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
135 val = (char *) re_compile_pattern ((char *) XSTRING (pattern)->data, 168 val = (char *) re_compile_pattern (raw_pattern, raw_pattern_size, &cp->buf);
136 XSTRING (pattern)->size, &cp->buf);
137 re_set_syntax (old); 169 re_set_syntax (old);
138 UNBLOCK_INPUT; 170 UNBLOCK_INPUT;
139 if (val) 171 if (val)
@@ -423,7 +455,7 @@ fast_c_string_match_ignore_case (regexp, string)
423 re_match_object = Qt; 455 re_match_object = Qt;
424 bufp = compile_pattern (regexp, 0, 456 bufp = compile_pattern (regexp, 0,
425 XCHAR_TABLE (Vascii_downcase_table)->contents, 0, 457 XCHAR_TABLE (Vascii_downcase_table)->contents, 0,
426 1); 458 0);
427 immediate_quit = 1; 459 immediate_quit = 1;
428 val = re_search (bufp, string, len, 0, len, 0); 460 val = re_search (bufp, string, len, 0, len, 0);
429 immediate_quit = 0; 461 immediate_quit = 0;
@@ -1078,8 +1110,46 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt, posix)
1078 BM_tab = (int *) alloca (0400 * sizeof (int)); 1110 BM_tab = (int *) alloca (0400 * sizeof (int));
1079#endif 1111#endif
1080 { 1112 {
1081 unsigned char *patbuf = (unsigned char *) alloca (len_byte); 1113 unsigned char *raw_pattern;
1114 int raw_pattern_size;
1115 unsigned char *patbuf;
1116 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
1117
1118 /* MULTIBYTE says whether the text to be searched is multibyte.
1119 We must convert PATTERN to match that, or we will not really
1120 find things right. */
1121
1122 if (multibyte == STRING_MULTIBYTE (string))
1123 {
1124 raw_pattern = (char *) XSTRING (string)->data;
1125 raw_pattern_size = XSTRING (string)->size_byte;
1126 }
1127 else if (multibyte)
1128 {
1129 raw_pattern_size = count_size_as_multibyte (XSTRING (string)->data,
1130 XSTRING (string)->size);
1131 raw_pattern = (char *) alloca (raw_pattern_size + 1);
1132 copy_text (XSTRING (string)->data, raw_pattern,
1133 XSTRING (string)->size, 0, 1);
1134 }
1135 else
1136 {
1137 /* Converting multibyte to single-byte.
1138
1139 ??? Perhaps this conversion should be done in a special way
1140 by subtracting nonascii-insert-offset from each non-ASCII char,
1141 so that only the multibyte chars which really correspond to
1142 the chosen single-byte character set can possibly match. */
1143 raw_pattern_size = XSTRING (string)->size;
1144 raw_pattern = (char *) alloca (raw_pattern_size + 1);
1145 copy_text (XSTRING (string)->data, raw_pattern,
1146 XSTRING (string)->size, 1, 0);
1147 }
1148
1149 len_byte = raw_pattern_size;
1150 patbuf = (unsigned char *) alloca (len_byte);
1082 pat = patbuf; 1151 pat = patbuf;
1152 base_pat = raw_pattern;
1083 while (--len_byte >= 0) 1153 while (--len_byte >= 0)
1084 { 1154 {
1085 /* If we got here and the RE flag is set, it's because we're 1155 /* If we got here and the RE flag is set, it's because we're