Mercurial > emacs
comparison src/syntax.c @ 20626:a39bcf9c0e1e
(skip_chars): Handle multibyte and unibyte strings
for either kind of buffer. Scan string by bytes and chars.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Fri, 09 Jan 1998 23:17:52 +0000 |
| parents | a475efff810e |
| children | fa7d4c0ee36c |
comparison
equal
deleted
inserted
replaced
| 20625:a9c4bf3f4e46 | 20626:a39bcf9c0e1e |
|---|---|
| 1211 character set because a range striding across character sets is | 1211 character set because a range striding across character sets is |
| 1212 meaningless. */ | 1212 meaningless. */ |
| 1213 int *char_ranges; | 1213 int *char_ranges; |
| 1214 int n_char_ranges = 0; | 1214 int n_char_ranges = 0; |
| 1215 int negate = 0; | 1215 int negate = 0; |
| 1216 register int i; | 1216 register int i, i_byte; |
| 1217 int multibyte = !NILP (current_buffer->enable_multibyte_characters); | 1217 int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
| 1218 int string_multibyte = STRING_MULTIBYTE (string); | |
| 1218 | 1219 |
| 1219 CHECK_STRING (string, 0); | 1220 CHECK_STRING (string, 0); |
| 1220 char_ranges = (int *) alloca (XSTRING (string)->size * (sizeof (int)) * 2); | 1221 char_ranges = (int *) alloca (XSTRING (string)->size * (sizeof (int)) * 2); |
| 1221 | 1222 |
| 1222 if (NILP (lim)) | 1223 if (NILP (lim)) |
| 1228 if (XINT (lim) > ZV) | 1229 if (XINT (lim) > ZV) |
| 1229 XSETFASTINT (lim, ZV); | 1230 XSETFASTINT (lim, ZV); |
| 1230 if (XINT (lim) < BEGV) | 1231 if (XINT (lim) < BEGV) |
| 1231 XSETFASTINT (lim, BEGV); | 1232 XSETFASTINT (lim, BEGV); |
| 1232 | 1233 |
| 1233 p = XSTRING (string)->data; | |
| 1234 pend = p + XSTRING (string)->size; | |
| 1235 bzero (fastmap, sizeof fastmap); | 1234 bzero (fastmap, sizeof fastmap); |
| 1236 | 1235 |
| 1237 if (p != pend && *p == '^') | 1236 i = 0, i_byte = 0; |
| 1238 { | 1237 |
| 1239 negate = 1; p++; | 1238 if (i < XSTRING (string)->size |
| 1239 && XSTRING (string)->data[0] == '^') | |
| 1240 { | |
| 1241 negate = 1; i++, i_byte++; | |
| 1240 } | 1242 } |
| 1241 | 1243 |
| 1242 /* Find the characters specified and set their elements of fastmap. | 1244 /* Find the characters specified and set their elements of fastmap. |
| 1243 If syntaxp, each character counts as itself. | 1245 If syntaxp, each character counts as itself. |
| 1244 Otherwise, handle backslashes and ranges specially. */ | 1246 Otherwise, handle backslashes and ranges specially. */ |
| 1245 | 1247 |
| 1246 while (p != pend) | 1248 while (i < XSTRING (string)->size) |
| 1247 { | 1249 { |
| 1248 c = *p; | 1250 int c_leading_code; |
| 1251 | |
| 1252 if (string_multibyte) | |
| 1253 { | |
| 1254 c_leading_code = XSTRING (string)->data[i_byte]; | |
| 1255 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); | |
| 1256 } | |
| 1257 else | |
| 1258 c = c_leading_code = XSTRING (string)->data[i++]; | |
| 1259 | |
| 1260 /* Convert multibyteness between what the string has | |
| 1261 and what the buffer has. */ | |
| 1249 if (multibyte) | 1262 if (multibyte) |
| 1250 { | 1263 { |
| 1251 ch = STRING_CHAR (p, pend - p); | 1264 if (c >= 0200 && c < 0400) |
| 1252 p += BYTES_BY_CHAR_HEAD (*p); | 1265 c += nonascii_insert_offset; |
| 1253 } | 1266 } |
| 1254 else | 1267 else |
| 1255 { | 1268 c &= 0377; |
| 1256 ch = c; | 1269 |
| 1257 p++; | |
| 1258 } | |
| 1259 if (syntaxp) | 1270 if (syntaxp) |
| 1260 fastmap[syntax_spec_code[c]] = 1; | 1271 fastmap[syntax_spec_code[c & 0377]] = 1; |
| 1261 else | 1272 else |
| 1262 { | 1273 { |
| 1263 if (c == '\\') | 1274 if (c == '\\') |
| 1264 { | 1275 { |
| 1265 if (p == pend) break; | 1276 if (i == XSTRING (string)->size) |
| 1266 c = *p++; | 1277 break; |
| 1278 | |
| 1279 if (string_multibyte) | |
| 1280 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); | |
| 1281 else | |
| 1282 c = XSTRING (string)->data[i++]; | |
| 1267 } | 1283 } |
| 1268 if (p != pend && *p == '-') | 1284 if (i == XSTRING (string)->size && XSTRING (string)->data[i] == '-') |
| 1269 { | 1285 { |
| 1270 unsigned int ch2; | 1286 unsigned int c2; |
| 1271 | 1287 |
| 1272 p++; | 1288 /* Skip over the dash. */ |
| 1273 if (p == pend) break; | 1289 i++, i_byte++; |
| 1274 if (SINGLE_BYTE_CHAR_P (ch)) | 1290 |
| 1275 while (c <= *p) | 1291 if (i == XSTRING (string)->size) |
| 1292 break; | |
| 1293 | |
| 1294 /* Get the end of the range. */ | |
| 1295 if (string_multibyte) | |
| 1296 FETCH_STRING_CHAR_ADVANCE (c2, string, i, i_byte); | |
| 1297 else | |
| 1298 c2 = XSTRING (string)->data[i++]; | |
| 1299 | |
| 1300 if (SINGLE_BYTE_CHAR_P (c)) | |
| 1301 while (c <= c2) | |
| 1276 { | 1302 { |
| 1277 fastmap[c] = 1; | 1303 fastmap[c] = 1; |
| 1278 c++; | 1304 c++; |
| 1279 } | 1305 } |
| 1280 else | 1306 else |
| 1281 { | 1307 { |
| 1282 fastmap[c] = 1; /* C is the base leading-code. */ | 1308 fastmap[c_leading_code] = 1; |
| 1283 ch2 = STRING_CHAR (p, pend - p); | 1309 if (c <= c2) |
| 1284 if (ch <= ch2) | 1310 { |
| 1285 char_ranges[n_char_ranges++] = ch, | 1311 char_ranges[n_char_ranges++] = c; |
| 1286 char_ranges[n_char_ranges++] = ch2; | 1312 char_ranges[n_char_ranges++] = c2; |
| 1313 } | |
| 1287 } | 1314 } |
| 1288 p += multibyte ? BYTES_BY_CHAR_HEAD (*p) : 1; | |
| 1289 } | 1315 } |
| 1290 else | 1316 else |
| 1291 { | 1317 { |
| 1292 fastmap[c] = 1; | 1318 fastmap[c_leading_code] = 1; |
| 1293 if (!SINGLE_BYTE_CHAR_P (ch)) | 1319 if (!SINGLE_BYTE_CHAR_P (c)) |
| 1294 { | 1320 { |
| 1295 char_ranges[n_char_ranges++] = ch; | 1321 char_ranges[n_char_ranges++] = c; |
| 1296 char_ranges[n_char_ranges++] = ch; | 1322 char_ranges[n_char_ranges++] = c; |
| 1297 } | 1323 } |
| 1298 } | 1324 } |
| 1299 } | 1325 } |
| 1300 } | 1326 } |
| 1301 | 1327 |
