Mercurial > emacs
comparison src/syntax.c @ 30596:48a9e9f4fd9d
(skip_chars): Fix handling of multibyte<->unibyte conversion.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Sat, 05 Aug 2000 01:45:10 +0000 |
parents | 1b2764b5b33a |
children | 9d47c133b357 |
comparison
equal
deleted
inserted
replaced
30595:d2c59f370faa | 30596:48a9e9f4fd9d |
---|---|
1346 int negate = 0; | 1346 int negate = 0; |
1347 register int i, i_byte; | 1347 register int i, i_byte; |
1348 int multibyte = !NILP (current_buffer->enable_multibyte_characters); | 1348 int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
1349 int string_multibyte; | 1349 int string_multibyte; |
1350 int size_byte; | 1350 int size_byte; |
1351 unsigned char *str; | |
1352 int len; | |
1351 | 1353 |
1352 CHECK_STRING (string, 0); | 1354 CHECK_STRING (string, 0); |
1353 char_ranges = (int *) alloca (XSTRING (string)->size * (sizeof (int)) * 2); | 1355 char_ranges = (int *) alloca (XSTRING (string)->size * (sizeof (int)) * 2); |
1354 string_multibyte = STRING_MULTIBYTE (string); | 1356 string_multibyte = STRING_MULTIBYTE (string); |
1357 str = XSTRING (string)->data; | |
1355 size_byte = STRING_BYTES (XSTRING (string)); | 1358 size_byte = STRING_BYTES (XSTRING (string)); |
1359 | |
1360 /* Adjust the multibyteness of the string to that of the buffer. */ | |
1361 if (multibyte != string_multibyte) | |
1362 { | |
1363 int nbytes; | |
1364 | |
1365 if (multibyte) | |
1366 nbytes = count_size_as_multibyte (XSTRING (string)->data, | |
1367 XSTRING (string)->size); | |
1368 else | |
1369 nbytes = XSTRING (string)->size; | |
1370 if (nbytes != size_byte) | |
1371 { | |
1372 str = (unsigned char *) alloca (nbytes); | |
1373 copy_text (XSTRING (string)->data, str, nbytes, | |
1374 string_multibyte, multibyte); | |
1375 size_byte = nbytes; | |
1376 } | |
1377 } | |
1356 | 1378 |
1357 if (NILP (lim)) | 1379 if (NILP (lim)) |
1358 XSETINT (lim, forwardp ? ZV : BEGV); | 1380 XSETINT (lim, forwardp ? ZV : BEGV); |
1359 else | 1381 else |
1360 CHECK_NUMBER_COERCE_MARKER (lim, 0); | 1382 CHECK_NUMBER_COERCE_MARKER (lim, 0); |
1365 if (XINT (lim) < BEGV) | 1387 if (XINT (lim) < BEGV) |
1366 XSETFASTINT (lim, BEGV); | 1388 XSETFASTINT (lim, BEGV); |
1367 | 1389 |
1368 bzero (fastmap, sizeof fastmap); | 1390 bzero (fastmap, sizeof fastmap); |
1369 | 1391 |
1370 i = 0, i_byte = 0; | 1392 i_byte = 0; |
1371 | 1393 |
1372 if (i_byte < size_byte | 1394 if (i_byte < size_byte |
1373 && XSTRING (string)->data[0] == '^') | 1395 && XSTRING (string)->data[0] == '^') |
1374 { | 1396 { |
1375 negate = 1; i++, i_byte++; | 1397 negate = 1; i_byte++; |
1376 } | 1398 } |
1377 | 1399 |
1378 /* Find the characters specified and set their elements of fastmap. | 1400 /* Find the characters specified and set their elements of fastmap. |
1379 If syntaxp, each character counts as itself. | 1401 If syntaxp, each character counts as itself. |
1380 Otherwise, handle backslashes and ranges specially. */ | 1402 Otherwise, handle backslashes and ranges specially. */ |
1381 | 1403 |
1382 while (i_byte < size_byte) | 1404 while (i_byte < size_byte) |
1383 { | 1405 { |
1384 int c_leading_code = XSTRING (string)->data[i_byte]; | 1406 int c_leading_code = str[i_byte]; |
1385 | 1407 |
1386 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); | 1408 c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte - i_byte, len); |
1387 | 1409 i_byte += len; |
1388 /* Convert multibyteness between what the string has | |
1389 and what the buffer has. */ | |
1390 if (multibyte) | |
1391 c = unibyte_char_to_multibyte (c); | |
1392 else | |
1393 c &= 0377; | |
1394 | 1410 |
1395 if (syntaxp) | 1411 if (syntaxp) |
1396 fastmap[syntax_spec_code[c & 0377]] = 1; | 1412 fastmap[syntax_spec_code[c & 0377]] = 1; |
1397 else | 1413 else |
1398 { | 1414 { |
1399 if (c == '\\') | 1415 if (c == '\\') |
1400 { | 1416 { |
1401 if (i_byte == size_byte) | 1417 if (i_byte == size_byte) |
1402 break; | 1418 break; |
1403 | 1419 |
1404 c_leading_code = XSTRING (string)->data[i_byte]; | 1420 c_leading_code = str[i_byte]; |
1405 FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte); | 1421 c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); |
1422 i_byte += len; | |
1406 } | 1423 } |
1407 if (i_byte < size_byte | 1424 if (i_byte < size_byte |
1408 && XSTRING (string)->data[i_byte] == '-') | 1425 && str[i_byte] == '-') |
1409 { | 1426 { |
1410 unsigned int c2, c2_leading_code; | 1427 unsigned int c2, c2_leading_code; |
1411 | 1428 |
1412 /* Skip over the dash. */ | 1429 /* Skip over the dash. */ |
1413 i++, i_byte++; | 1430 i_byte++; |
1414 | 1431 |
1415 if (i_byte == size_byte) | 1432 if (i_byte == size_byte) |
1416 break; | 1433 break; |
1417 | 1434 |
1418 /* Get the end of the range. */ | 1435 /* Get the end of the range. */ |
1419 c2_leading_code = XSTRING (string)->data[i_byte]; | 1436 c2_leading_code = str[i_byte]; |
1420 FETCH_STRING_CHAR_ADVANCE (c2, string, i, i_byte); | 1437 c2 =STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); |
1438 i_byte += len; | |
1421 | 1439 |
1422 if (SINGLE_BYTE_CHAR_P (c)) | 1440 if (SINGLE_BYTE_CHAR_P (c)) |
1423 { | 1441 { |
1424 if (! SINGLE_BYTE_CHAR_P (c2)) | 1442 if (! SINGLE_BYTE_CHAR_P (c2)) |
1425 error ("Invalid character range: %s", | 1443 error ("Invalid character range: %s", |