1345 |
{ |
{ |
1346 |
const unsigned char *p = SDATA (string); |
const unsigned char *p = SDATA (string); |
1347 |
const unsigned char *endp = p + SBYTES (string); |
const unsigned char *endp = p + SBYTES (string); |
|
struct charset *charset; |
|
1348 |
|
|
1349 |
if (SCHARS (string) == SBYTES (string)) |
if (SCHARS (string) == SBYTES (string)) |
1350 |
return 0; |
return 0; |
1351 |
|
|
|
charset = CHARSET_FROM_ID (charset_iso_8859_1); |
|
1352 |
while (p < endp) |
while (p < endp) |
1353 |
{ |
{ |
1354 |
int c = STRING_CHAR_ADVANCE (p); |
int c = STRING_CHAR_ADVANCE (p); |
1355 |
|
|
1356 |
/* Fixme: comparison of unsigned expression < 0 is always false */ |
if (c >= 0x100) |
|
if (ENCODE_CHAR (charset, c) < 0) |
|
1357 |
return 2; |
return 2; |
1358 |
} |
} |
1359 |
return 1; |
return 1; |
1362 |
|
|
1363 |
/* Find charsets in the string at PTR of NCHARS and NBYTES. |
/* Find charsets in the string at PTR of NCHARS and NBYTES. |
1364 |
|
|
1365 |
CHARSETS is a vector. Each element is a cons of CHARSET and |
CHARSETS is a vector. If Nth element is non-nil, it means the |
1366 |
FOUND-FLAG. CHARSET is a charset id, and FOUND-FLAG is nil or t. |
charset whose id is N is already found. |
|
FOUND-FLAG t (or nil) means that the corresponding charset is |
|
|
already found (or not yet found). |
|
1367 |
|
|
1368 |
It may lookup a translation table TABLE if supplied. */ |
It may lookup a translation table TABLE if supplied. */ |
1369 |
|
|
1370 |
static void |
static void |
1371 |
find_charsets_in_text (ptr, nchars, nbytes, charsets, table) |
find_charsets_in_text (ptr, nchars, nbytes, charsets, table, multibyte) |
1372 |
const unsigned char *ptr; |
const unsigned char *ptr; |
1373 |
EMACS_INT nchars, nbytes; |
EMACS_INT nchars, nbytes; |
1374 |
Lisp_Object charsets, table; |
Lisp_Object charsets, table; |
1375 |
|
int multibyte; |
1376 |
{ |
{ |
1377 |
const unsigned char *pend = ptr + nbytes; |
const unsigned char *pend = ptr + nbytes; |
1378 |
int ncharsets = ASIZE (charsets); |
int ncharsets = ASIZE (charsets); |
1379 |
|
|
1380 |
if (nchars == nbytes) |
if (nchars == nbytes) |
|
return; |
|
|
|
|
|
while (ptr < pend) |
|
1381 |
{ |
{ |
1382 |
int c = STRING_CHAR_ADVANCE (ptr); |
if (multibyte) |
1383 |
int i; |
ASET (charsets, charset_ascii, Qt); |
1384 |
int all_found = 1; |
else |
1385 |
Lisp_Object elt; |
while (ptr < pend) |
1386 |
|
{ |
1387 |
if (!NILP (table)) |
int c = *ptr++; |
1388 |
c = translate_char (table, c); |
|
1389 |
for (i = 0; i < ncharsets; i++) |
if (!NILP (table)) |
1390 |
|
c = translate_char (table, c); |
1391 |
|
if (ASCII_BYTE_P (c)) |
1392 |
|
ASET (charsets, charset_ascii, Qt); |
1393 |
|
else |
1394 |
|
ASET (charsets, charset_eight_bit, Qt); |
1395 |
|
} |
1396 |
|
} |
1397 |
|
else |
1398 |
|
{ |
1399 |
|
while (ptr < pend) |
1400 |
{ |
{ |
1401 |
elt = AREF (charsets, i); |
int c = STRING_CHAR_ADVANCE (ptr); |
1402 |
if (NILP (XCDR (elt))) |
struct charset *charset; |
|
{ |
|
|
struct charset *charset = CHARSET_FROM_ID (XINT (XCAR (elt))); |
|
1403 |
|
|
1404 |
if (ENCODE_CHAR (charset, c) != CHARSET_INVALID_CODE (charset)) |
if (!NILP (table)) |
1405 |
XSETCDR (elt, Qt); |
c = translate_char (table, c); |
1406 |
else |
charset = CHAR_CHARSET (c); |
1407 |
all_found = 0; |
ASET (charsets, CHARSET_ID (charset), Qt); |
|
} |
|
1408 |
} |
} |
|
if (all_found) |
|
|
break; |
|
1409 |
} |
} |
1410 |
} |
} |
1411 |
|
|
|
/* Fixme: returns nil for unibyte. */ |
|
1412 |
DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region, |
DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region, |
1413 |
2, 3, 0, |
2, 3, 0, |
1414 |
doc: /* Return a list of charsets in the region between BEG and END. |
doc: /* Return a list of charsets in the region between BEG and END. |
1424 |
EMACS_INT from, from_byte, to, stop, stop_byte; |
EMACS_INT from, from_byte, to, stop, stop_byte; |
1425 |
int i; |
int i; |
1426 |
Lisp_Object val; |
Lisp_Object val; |
1427 |
|
int multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
1428 |
|
|
1429 |
validate_region (&beg, &end); |
validate_region (&beg, &end); |
1430 |
from = XFASTINT (beg); |
from = XFASTINT (beg); |
1441 |
from_byte = CHAR_TO_BYTE (from); |
from_byte = CHAR_TO_BYTE (from); |
1442 |
|
|
1443 |
charsets = Fmake_vector (make_number (charset_table_used), Qnil); |
charsets = Fmake_vector (make_number (charset_table_used), Qnil); |
|
for (i = 0; i < charset_table_used; i++) |
|
|
ASET (charsets, i, Fcons (make_number (i), Qnil)); |
|
|
|
|
1444 |
while (1) |
while (1) |
1445 |
{ |
{ |
1446 |
find_charsets_in_text (BYTE_POS_ADDR (from_byte), stop - from, |
find_charsets_in_text (BYTE_POS_ADDR (from_byte), stop - from, |
1447 |
stop_byte - from_byte, charsets, table); |
stop_byte - from_byte, charsets, table, |
1448 |
|
multibyte); |
1449 |
if (stop < to) |
if (stop < to) |
1450 |
{ |
{ |
1451 |
from = stop, from_byte = stop_byte; |
from = stop, from_byte = stop_byte; |
1457 |
|
|
1458 |
val = Qnil; |
val = Qnil; |
1459 |
for (i = charset_table_used - 1; i >= 0; i--) |
for (i = charset_table_used - 1; i >= 0; i--) |
1460 |
if (!NILP (XCDR (AREF (charsets, i)))) |
if (!NILP (AREF (charsets, i))) |
1461 |
val = Fcons (CHARSET_NAME (charset_table + i), val); |
val = Fcons (CHARSET_NAME (charset_table + i), val); |
1462 |
return val; |
return val; |
1463 |
} |
} |
1464 |
|
|
|
/* Fixme: returns nil for unibyte. */ |
|
1465 |
DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string, |
DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string, |
1466 |
1, 2, 0, |
1, 2, 0, |
1467 |
doc: /* Return a list of charsets in STR. |
doc: /* Return a list of charsets in STR. |
1479 |
CHECK_STRING (str); |
CHECK_STRING (str); |
1480 |
|
|
1481 |
charsets = Fmake_vector (make_number (charset_table_used), Qnil); |
charsets = Fmake_vector (make_number (charset_table_used), Qnil); |
|
for (i = 0; i < charset_table_used; i++) |
|
|
ASET (charsets, i, Fcons (make_number (i), Qnil)); |
|
1482 |
find_charsets_in_text (SDATA (str), SCHARS (str), SBYTES (str), |
find_charsets_in_text (SDATA (str), SCHARS (str), SBYTES (str), |
1483 |
charsets, table); |
charsets, table, |
1484 |
|
STRING_MULTIBYTE (str)); |
1485 |
val = Qnil; |
val = Qnil; |
1486 |
for (i = charset_table_used - 1; i >= 0; i--) |
for (i = charset_table_used - 1; i >= 0; i--) |
1487 |
if (!NILP (XCDR (AREF (charsets, i)))) |
if (!NILP (AREF (charsets, i))) |
1488 |
val = Fcons (CHARSET_NAME (charset_table + i), val); |
val = Fcons (CHARSET_NAME (charset_table + i), val); |
1489 |
return val; |
return val; |
1490 |
} |
} |
1839 |
} |
} |
1840 |
|
|
1841 |
|
|
|
/* Fixme: `unknown' can't happen now? */ |
|
1842 |
DEFUN ("split-char", Fsplit_char, Ssplit_char, 1, 1, 0, |
DEFUN ("split-char", Fsplit_char, Ssplit_char, 1, 1, 0, |
1843 |
doc: /*Return list of charset and one to three position-codes of CHAR. |
doc: |
1844 |
If CHAR is invalid as a character code, return a list `(unknown CHAR)'. */) |
/*Return list of charset and one to four position-codes of CHAR. |
1845 |
|
The charset is decided by the current priority order of charsets. |
1846 |
|
A position-code is a byte value of each dimension of the code-point of |
1847 |
|
CHAR in the charset. */) |
1848 |
(ch) |
(ch) |
1849 |
Lisp_Object ch; |
Lisp_Object ch; |
1850 |
{ |
{ |
1857 |
c = XFASTINT (ch); |
c = XFASTINT (ch); |
1858 |
charset = CHAR_CHARSET (c); |
charset = CHAR_CHARSET (c); |
1859 |
if (! charset) |
if (! charset) |
1860 |
return Fcons (intern ("unknown"), Fcons (ch, Qnil)); |
abort (); |
|
|
|
1861 |
code = ENCODE_CHAR (charset, c); |
code = ENCODE_CHAR (charset, c); |
1862 |
if (code == CHARSET_INVALID_CODE (charset)) |
if (code == CHARSET_INVALID_CODE (charset)) |
1863 |
abort (); |
abort (); |
1864 |
dimension = CHARSET_DIMENSION (charset); |
dimension = CHARSET_DIMENSION (charset); |
1865 |
val = (dimension == 1 ? Fcons (make_number (code), Qnil) |
for (val = Qnil; dimension > 0; dimension--) |
1866 |
: dimension == 2 ? Fcons (make_number (code >> 8), |
{ |
1867 |
Fcons (make_number (code & 0xFF), Qnil)) |
val = Fcons (make_number (code & 0xFF), val); |
1868 |
: Fcons (make_number (code >> 16), |
code >>= 8; |
1869 |
Fcons (make_number ((code >> 8) & 0xFF), |
} |
|
Fcons (make_number (code & 0xFF), Qnil)))); |
|
1870 |
return Fcons (CHARSET_NAME (charset), val); |
return Fcons (CHARSET_NAME (charset), val); |
1871 |
} |
} |
1872 |
|
|