comparison src/syntax.c @ 17564:050f15e0b948

(skip_chars): Merge mule changes back in.
author Richard M. Stallman <rms@gnu.org>
date Fri, 25 Apr 1997 21:59:44 +0000
parents c6ba5208968b
children aefc22e52046
comparison
equal deleted inserted replaced
17563:b696f990c544 17564:050f15e0b948
1131 int forwardp, syntaxp; 1131 int forwardp, syntaxp;
1132 Lisp_Object string, lim; 1132 Lisp_Object string, lim;
1133 { 1133 {
1134 register unsigned char *p, *pend; 1134 register unsigned char *p, *pend;
1135 register unsigned int c; 1135 register unsigned int c;
1136 register int ch;
1136 unsigned char fastmap[0400]; 1137 unsigned char fastmap[0400];
1138 /* If SYNTAXP is 0, STRING may contain multi-byte form of characters
1139 of which codes don't fit in FASTMAP. In that case, we set the
1140 first byte of multibyte form (i.e. base leading-code) in FASTMAP
1141 and set the actual ranges of characters in CHAR_RANGES. In the
1142 form "X-Y" of STRING, both X and Y must belong to the same
1143 character set because a range striding across character sets is
1144 meaningless. */
1145 int *char_ranges
1146 = (int *) alloca (XSTRING (string)->size * (sizeof (int)) * 2);
1147 int n_char_ranges = 0;
1137 int negate = 0; 1148 int negate = 0;
1138 register int i; 1149 register int i;
1150 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
1139 1151
1140 CHECK_STRING (string, 0); 1152 CHECK_STRING (string, 0);
1141 1153
1142 if (NILP (lim)) 1154 if (NILP (lim))
1143 XSETINT (lim, forwardp ? ZV : BEGV); 1155 XSETINT (lim, forwardp ? ZV : BEGV);
1166 If syntaxp, each character counts as itself. 1178 If syntaxp, each character counts as itself.
1167 Otherwise, handle backslashes and ranges specially. */ 1179 Otherwise, handle backslashes and ranges specially. */
1168 1180
1169 while (p != pend) 1181 while (p != pend)
1170 { 1182 {
1171 c = *p++; 1183 c = *p;
1184 if (multibyte)
1185 {
1186 ch = STRING_CHAR (p, pend - p);
1187 p += BYTES_BY_CHAR_HEAD (*p);
1188 }
1189 else
1190 {
1191 ch = c;
1192 p++;
1193 }
1172 if (syntaxp) 1194 if (syntaxp)
1173 fastmap[syntax_spec_code[c]] = 1; 1195 fastmap[syntax_spec_code[c]] = 1;
1174 else 1196 else
1175 { 1197 {
1176 if (c == '\\') 1198 if (c == '\\')
1178 if (p == pend) break; 1200 if (p == pend) break;
1179 c = *p++; 1201 c = *p++;
1180 } 1202 }
1181 if (p != pend && *p == '-') 1203 if (p != pend && *p == '-')
1182 { 1204 {
1205 unsigned int ch2;
1206
1183 p++; 1207 p++;
1184 if (p == pend) break; 1208 if (p == pend) break;
1185 while (c <= *p) 1209 if (SINGLE_BYTE_CHAR_P (ch))
1210 while (c <= *p)
1211 {
1212 fastmap[c] = 1;
1213 c++;
1214 }
1215 else
1186 { 1216 {
1187 fastmap[c] = 1; 1217 fastmap[c] = 1; /* C is the base leading-code. */
1188 c++; 1218 ch2 = STRING_CHAR (p, pend - p);
1219 if (ch <= ch2)
1220 char_ranges[n_char_ranges++] = ch,
1221 char_ranges[n_char_ranges++] = ch2;
1189 } 1222 }
1190 p++; 1223 p += multibyte ? BYTES_BY_CHAR_HEAD (*p) : 1;
1191 } 1224 }
1192 else 1225 else
1193 fastmap[c] = 1; 1226 {
1194 } 1227 fastmap[c] = 1;
1195 } 1228 if (!SINGLE_BYTE_CHAR_P (ch))
1196 1229 {
1197 /* If ^ was the first character, complement the fastmap. */ 1230 char_ranges[n_char_ranges++] = ch;
1231 char_ranges[n_char_ranges++] = ch;
1232 }
1233 }
1234 }
1235 }
1236
1237 /* If ^ was the first character, complement the fastmap. In
1238 addition, as all multibyte characters have possibility of
1239 matching, set all entries for base leading codes, which is
1240 harmless even if SYNTAXP is 1. */
1198 1241
1199 if (negate) 1242 if (negate)
1200 for (i = 0; i < sizeof fastmap; i++) 1243 for (i = 0; i < sizeof fastmap; i++)
1201 fastmap[i] ^= 1; 1244 {
1245 if (!multibyte || !BASE_LEADING_CODE_P (i))
1246 fastmap[i] ^= 1;
1247 else
1248 fastmap[i] = 1;
1249 }
1202 1250
1203 { 1251 {
1204 int start_point = PT; 1252 int start_point = PT;
1205 int pos = PT; 1253 int pos = PT;
1206 1254
1208 if (syntaxp) 1256 if (syntaxp)
1209 { 1257 {
1210 SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1); 1258 SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1);
1211 if (forwardp) 1259 if (forwardp)
1212 { 1260 {
1213 while (pos < XINT (lim) 1261 if (multibyte)
1214 && fastmap[(int) SYNTAX (FETCH_CHAR (pos))])
1215 { 1262 {
1216 pos++; 1263 while (pos < XINT (lim)
1217 UPDATE_SYNTAX_TABLE_FORWARD (pos); 1264 && fastmap[(int) SYNTAX (FETCH_CHAR (pos))])
1265 {
1266 INC_POS (pos);
1267 UPDATE_SYNTAX_TABLE_FORWARD (pos);
1268 }
1269 }
1270 else
1271 {
1272 while (pos < XINT (lim)
1273 && fastmap[(int) SYNTAX (FETCH_BYTE (pos))])
1274 {
1275 pos++;
1276 UPDATE_SYNTAX_TABLE_FORWARD (pos);
1277 }
1218 } 1278 }
1219 } 1279 }
1220 else 1280 else
1221 { 1281 {
1222 while (pos > XINT (lim) 1282 if (multibyte)
1223 && fastmap[(int) SYNTAX (FETCH_CHAR (pos - 1))])
1224 { 1283 {
1225 pos--; 1284 while (pos > XINT (lim))
1226 UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); 1285 {
1286 int savepos = pos;
1287 DEC_POS (pos);
1288 if (!fastmap[(int) SYNTAX (FETCH_CHAR (pos))])
1289 {
1290 pos = savepos;
1291 break;
1292 }
1293 UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
1294 }
1295 }
1296 else
1297 {
1298 while (pos > XINT (lim)
1299 && fastmap[(int) SYNTAX (FETCH_BYTE (pos - 1))])
1300 {
1301 pos--;
1302 UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
1303 }
1227 } 1304 }
1228 } 1305 }
1229 } 1306 }
1230 else 1307 else
1231 { 1308 {
1232 if (forwardp) 1309 if (forwardp)
1233 { 1310 {
1234 while (pos < XINT (lim) && fastmap[FETCH_CHAR (pos)]) 1311 if (multibyte)
1235 pos++; 1312 while (pos < XINT (lim) && fastmap[(c = FETCH_BYTE (pos))])
1313 {
1314 if (!BASE_LEADING_CODE_P (c))
1315 pos++;
1316 else if (n_char_ranges)
1317 {
1318 /* We much check CHAR_RANGES for a multibyte
1319 character. */
1320 ch = FETCH_MULTIBYTE_CHAR (pos);
1321 for (i = 0; i < n_char_ranges; i += 2)
1322 if ((ch >= char_ranges[i] && ch <= char_ranges[i + 1]))
1323 break;
1324 if (!(negate ^ (i < n_char_ranges)))
1325 break;
1326
1327 INC_POS (pos);
1328 }
1329 else
1330 {
1331 if (!negate) break;
1332 INC_POS (pos);
1333 }
1334 }
1335 else
1336 while (pos < XINT (lim) && fastmap[FETCH_BYTE (pos)])
1337 pos++;
1236 } 1338 }
1237 else 1339 else
1238 { 1340 {
1239 while (pos > XINT (lim) && fastmap[FETCH_CHAR (pos - 1)]) 1341 if (multibyte)
1240 pos--; 1342 while (pos > XINT (lim))
1343 {
1344 int savepos = pos;
1345 DEC_POS (pos);
1346 if (fastmap[(c = FETCH_BYTE (pos))])
1347 {
1348 if (!BASE_LEADING_CODE_P (c))
1349 ;
1350 else if (n_char_ranges)
1351 {
1352 /* We much check CHAR_RANGES for a multibyte
1353 character. */
1354 ch = FETCH_MULTIBYTE_CHAR (pos);
1355 for (i = 0; i < n_char_ranges; i += 2)
1356 if (ch >= char_ranges[i] && ch <= char_ranges[i + 1])
1357 break;
1358 if (!(negate ^ (i < n_char_ranges)))
1359 {
1360 pos = savepos;
1361 break;
1362 }
1363 }
1364 else
1365 if (!negate)
1366 {
1367 pos = savepos;
1368 break;
1369 }
1370 }
1371 else
1372 {
1373 pos = savepos;
1374 break;
1375 }
1376 }
1377 else
1378 while (pos > XINT (lim) && fastmap[FETCH_BYTE (pos - 1)])
1379 pos--;
1241 } 1380 }
1242 } 1381 }
1382
1383 if (multibyte
1384 /* INC_POS or DEC_POS might have moved POS over LIM. */
1385 && (forwardp ? (pos > XINT (lim)) : (pos < XINT (lim))))
1386 pos = XINT (lim);
1387
1243 SET_PT (pos); 1388 SET_PT (pos);
1244 immediate_quit = 0; 1389 immediate_quit = 0;
1245 1390
1246 return make_number (PT - start_point); 1391 return make_number (PT - start_point);
1247 } 1392 }