diff options
| author | Richard M. Stallman | 1998-01-09 23:17:52 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-01-09 23:17:52 +0000 |
| commit | 4101e6fea44e7ed0106dc095557aa1fa1515c069 (patch) | |
| tree | b6b700f02eda08f9cee8f4249c2d857b8ec756a0 /src | |
| parent | a1b5012f8aada770dda68c83afd8880fbda9f356 (diff) | |
| download | emacs-4101e6fea44e7ed0106dc095557aa1fa1515c069.tar.gz emacs-4101e6fea44e7ed0106dc095557aa1fa1515c069.zip | |
(skip_chars): Handle multibyte and unibyte strings
for either kind of buffer. Scan string by bytes and chars.
Diffstat (limited to 'src')
| -rw-r--r-- | src/syntax.c | 88 |
1 files changed, 57 insertions, 31 deletions
diff --git a/src/syntax.c b/src/syntax.c index 97e8591ba15..e80ecc4a279 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -1213,8 +1213,9 @@ skip_chars (forwardp, syntaxp, string, lim) | |||
| 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); |
| @@ -1230,70 +1231,95 @@ skip_chars (forwardp, syntaxp, string, lim) | |||
| 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; |
| 1237 | |||
| 1238 | if (i < XSTRING (string)->size | ||
| 1239 | && XSTRING (string)->data[0] == '^') | ||
| 1238 | { | 1240 | { |
| 1239 | negate = 1; p++; | 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; |
| 1249 | if (multibyte) | 1251 | |
| 1252 | if (string_multibyte) | ||
| 1250 | { | 1253 | { |
| 1251 | ch = STRING_CHAR (p, pend - p); | 1254 | c_leading_code = XSTRING (string)->data[i_byte]; |
| 1252 | p += BYTES_BY_CHAR_HEAD (*p); | 1255 | FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); |
| 1253 | } | 1256 | } |
| 1254 | else | 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. */ | ||
| 1262 | if (multibyte) | ||
| 1255 | { | 1263 | { |
| 1256 | ch = c; | 1264 | if (c >= 0200 && c < 0400) |
| 1257 | p++; | 1265 | c += nonascii_insert_offset; |
| 1258 | } | 1266 | } |
| 1267 | else | ||
| 1268 | c &= 0377; | ||
| 1269 | |||
| 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; |
| 1287 | |||
| 1288 | /* Skip over the dash. */ | ||
| 1289 | i++, i_byte++; | ||
| 1290 | |||
| 1291 | if (i == XSTRING (string)->size) | ||
| 1292 | break; | ||
| 1271 | 1293 | ||
| 1272 | p++; | 1294 | /* Get the end of the range. */ |
| 1273 | if (p == pend) break; | 1295 | if (string_multibyte) |
| 1274 | if (SINGLE_BYTE_CHAR_P (ch)) | 1296 | FETCH_STRING_CHAR_ADVANCE (c2, string, i, i_byte); |
| 1275 | while (c <= *p) | 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 | } |