1 /* Header for multibyte character handler.
2    Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.
3      Licensed to the Free Software Foundation.
4    Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5      National Institute of Advanced Industrial Science and Technology (AIST)
6      Registration Number H13PRO009
7 
8 This file is part of GNU Emacs.
9 
10 GNU Emacs is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or (at
13 your option) any later version.
14 
15 GNU Emacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
22 
23 #ifndef EMACS_CHARACTER_H
24 #define EMACS_CHARACTER_H
25 
26 #include <verify.h>
27 #include "lisp.h"
28 
29 INLINE_HEADER_BEGIN
30 
31 /* character code	1st byte   byte sequence
32    --------------	--------   -------------
33         0-7F		00..7F	   0xxxxxxx
34        80-7FF		C2..DF	   110yyyyx 10xxxxxx
35       800-FFFF		E0..EF	   1110yyyy 10yxxxxx 10xxxxxx
36     10000-1FFFFF	F0..F7	   11110yyy 10yyxxxx 10xxxxxx 10xxxxxx
37    200000-3FFF7F	F8	   11111000 1000yxxx 10xxxxxx 10xxxxxx 10xxxxxx
38    3FFF80-3FFFFF	C0..C1	   1100000x 10xxxxxx (for eight-bit-char)
39    400000-...		invalid
40 
41    invalid 1st byte	80..BF	   10xxxxxx
42 			F9..FF	   11111yyy
43 
44    In each bit pattern, 'x' and 'y' each represent a single bit of the
45    character code payload, and at least one 'y' must be a 1 bit.
46    In the 5-byte sequence, the 22-bit payload cannot exceed 3FFF7F.
47 */
48 
49 /* Maximum character code ((1 << CHARACTERBITS) - 1).  */
50 enum { MAX_CHAR = 0x3FFFFF };
51 
52 /* Maximum Unicode character code.  */
53 enum { MAX_UNICODE_CHAR = 0x10FFFF };
54 
55 /* Maximum N-byte character codes.  */
56 enum { MAX_1_BYTE_CHAR = 0x7F };
57 enum { MAX_2_BYTE_CHAR = 0x7FF };
58 enum { MAX_3_BYTE_CHAR = 0xFFFF };
59 enum { MAX_4_BYTE_CHAR = 0x1FFFFF };
60 enum { MAX_5_BYTE_CHAR = 0x3FFF7F };
61 
62 /* Minimum leading code of multibyte characters.  */
63 enum { MIN_MULTIBYTE_LEADING_CODE = 0xC0 };
64 /* Maximum leading code of multibyte characters.  Note: this must be
65    updated if we ever increase MAX_CHAR above.  */
66 enum { MAX_MULTIBYTE_LEADING_CODE = 0xF8 };
67 
68 /* Unicode character values.  */
69 enum
70 {
71   NO_BREAK_SPACE = 0x00A0,
72   SOFT_HYPHEN = 0x00AD,
73   ZERO_WIDTH_NON_JOINER = 0x200C,
74   ZERO_WIDTH_JOINER = 0x200D,
75   HYPHEN = 0x2010,
76   NON_BREAKING_HYPHEN = 0x2011,
77   LEFT_SINGLE_QUOTATION_MARK = 0x2018,
78   RIGHT_SINGLE_QUOTATION_MARK = 0x2019,
79   PARAGRAPH_SEPARATOR = 0x2029,
80   LEFT_POINTING_ANGLE_BRACKET = 0x2329,
81   RIGHT_POINTING_ANGLE_BRACKET = 0x232A,
82   LEFT_ANGLE_BRACKET = 0x3008,
83   RIGHT_ANGLE_BRACKET = 0x3009,
84   OBJECT_REPLACEMENT_CHARACTER = 0xFFFC,
85   TAG_SPACE = 0xE0020,
86   CANCEL_TAG = 0xE007F,
87 };
88 
89 extern int char_string (unsigned, unsigned char *);
90 
91 /* UTF-8 encodings.  Use \x escapes, so they are portable to pre-C11
92    compilers and can be concatenated with ordinary string literals.  */
93 #define uLSQM "\xE2\x80\x98" /* U+2018 LEFT SINGLE QUOTATION MARK */
94 #define uRSQM "\xE2\x80\x99" /* U+2019 RIGHT SINGLE QUOTATION MARK */
95 
96 /* True iff C is a character of code less than 0x100.  */
97 INLINE bool
SINGLE_BYTE_CHAR_P(intmax_t c)98 SINGLE_BYTE_CHAR_P (intmax_t c)
99 {
100   return 0 <= c && c < 0x100;
101 }
102 
103 /* True iff C is a character that corresponds to a raw 8-bit
104    byte.  */
105 INLINE bool
CHAR_BYTE8_P(int c)106 CHAR_BYTE8_P (int c)
107 {
108   return MAX_5_BYTE_CHAR < c;
109 }
110 
111 /* Return the character code for raw 8-bit byte BYTE.  */
112 INLINE int
BYTE8_TO_CHAR(int byte)113 BYTE8_TO_CHAR (int byte)
114 {
115   return byte + 0x3FFF00;
116 }
117 
118 INLINE int
UNIBYTE_TO_CHAR(int byte)119 UNIBYTE_TO_CHAR (int byte)
120 {
121   return ASCII_CHAR_P (byte) ? byte : BYTE8_TO_CHAR (byte);
122 }
123 
124 /* Return the raw 8-bit byte for character C.  */
125 INLINE int
CHAR_TO_BYTE8(int c)126 CHAR_TO_BYTE8 (int c)
127 {
128   return CHAR_BYTE8_P (c) ? c - 0x3FFF00 : c & 0xFF;
129 }
130 
131 /* Return the raw 8-bit byte for character C,
132    or -1 if C doesn't correspond to a byte.  */
133 INLINE int
CHAR_TO_BYTE_SAFE(int c)134 CHAR_TO_BYTE_SAFE (int c)
135 {
136   return ASCII_CHAR_P (c) ? c : CHAR_BYTE8_P (c) ? c - 0x3FFF00 : -1;
137 }
138 
139 /* True iff BYTE is the 1st byte of a multibyte form of a character
140    that corresponds to a raw 8-bit byte.  */
141 INLINE bool
CHAR_BYTE8_HEAD_P(int byte)142 CHAR_BYTE8_HEAD_P (int byte)
143 {
144   return byte == 0xC0 || byte == 0xC1;
145 }
146 
147 /* If C is not ASCII, make it multibyte.  Assumes C < 256.  */
148 INLINE int
make_char_multibyte(int c)149 make_char_multibyte (int c)
150 {
151   eassert (SINGLE_BYTE_CHAR_P (c));
152   return UNIBYTE_TO_CHAR (c);
153 }
154 
155 /* This is the maximum byte length of multibyte form.  */
156 enum { MAX_MULTIBYTE_LENGTH = 5 };
157 
158 /* Nonzero iff C is valid as a character code.  */
159 INLINE bool
CHAR_VALID_P(intmax_t c)160 CHAR_VALID_P (intmax_t c)
161 {
162   return 0 <= c && c <= MAX_CHAR;
163 }
164 
165 /* Nonzero iff X is a character.  */
166 INLINE bool
CHARACTERP(Lisp_Object x)167 CHARACTERP (Lisp_Object x)
168 {
169   return FIXNUMP (x) && CHAR_VALID_P (XFIXNUM (x));
170 }
171 
172 /* Check if Lisp object X is a character or not.  */
173 INLINE void
CHECK_CHARACTER(Lisp_Object x)174 CHECK_CHARACTER (Lisp_Object x)
175 {
176   CHECK_TYPE (CHARACTERP (x), Qcharacterp, x);
177 }
178 
179 INLINE void
CHECK_CHARACTER_CAR(Lisp_Object x)180 CHECK_CHARACTER_CAR (Lisp_Object x)
181 {
182   CHECK_CHARACTER (XCAR (x));
183 }
184 
185 INLINE void
CHECK_CHARACTER_CDR(Lisp_Object x)186 CHECK_CHARACTER_CDR (Lisp_Object x)
187 {
188   CHECK_CHARACTER (XCDR (x));
189 }
190 
191 /* True if character C has a printable glyph.  */
192 INLINE bool
CHAR_PRINTABLE_P(int c)193 CHAR_PRINTABLE_P (int c)
194 {
195   return ((32 <= c && c < 127)
196 	  || ! NILP (CHAR_TABLE_REF (Vprintable_chars, c)));
197 }
198 
199 /* Return byte length of multibyte form for character C.  */
200 INLINE int
CHAR_BYTES(int c)201 CHAR_BYTES (int c)
202 {
203   return ((MAX_5_BYTE_CHAR < c ? -2 : 1)
204 	  + (MAX_1_BYTE_CHAR < c)
205 	  + (MAX_2_BYTE_CHAR < c)
206 	  + (MAX_3_BYTE_CHAR < c)
207 	  + (MAX_4_BYTE_CHAR < c));
208 }
209 
210 /* Return the leading code of multibyte form of C.  */
211 INLINE int
CHAR_LEADING_CODE(int c)212 CHAR_LEADING_CODE (int c)
213 {
214   return (c <= MAX_1_BYTE_CHAR ? c
215 	  : c <= MAX_2_BYTE_CHAR ? 0xC0 | (c >> 6)
216 	  : c <= MAX_3_BYTE_CHAR ? 0xE0 | (c >> 12)
217 	  : c <= MAX_4_BYTE_CHAR ? 0xF0 | (c >> 18)
218 	  : c <= MAX_5_BYTE_CHAR ? 0xF8
219 	  : 0xC0 | ((c >> 6) & 0x01));
220 }
221 
222 
223 /* Store multibyte form of the character C in P.  The caller should
224    allocate at least MAX_MULTIBYTE_LENGTH bytes area at P in advance.
225    Returns the length of the multibyte form.  */
226 
227 INLINE int
CHAR_STRING(int c,unsigned char * p)228 CHAR_STRING (int c, unsigned char *p)
229 {
230   eassume (0 <= c);
231   if (c <= MAX_1_BYTE_CHAR)
232     {
233       p[0] = c;
234       return 1;
235     }
236   if (c <= MAX_2_BYTE_CHAR)
237     {
238       p[0] = 0xC0 | (c >> 6);
239       p[1] = 0x80 | (c & 0x3F);
240       return 2;
241     }
242   if (c <= MAX_3_BYTE_CHAR)
243     {
244       p[0] = 0xE0 | (c >> 12);
245       p[1] = 0x80 | ((c >> 6) & 0x3F);
246       p[2] = 0x80 | (c & 0x3F);
247       return 3;
248     }
249   int len = char_string (c, p);
250   eassume (0 < len && len <= MAX_MULTIBYTE_LENGTH);
251   return len;
252 }
253 
254 /* Store multibyte form of byte B in P.  The caller should allocate at
255    least MAX_MULTIBYTE_LENGTH bytes area at P in advance.  Returns the
256    length of the multibyte form.  */
257 
258 INLINE int
BYTE8_STRING(int b,unsigned char * p)259 BYTE8_STRING (int b, unsigned char *p)
260 {
261   p[0] = 0xC0 | ((b >> 6) & 0x01);
262   p[1] = 0x80 | (b & 0x3F);
263   return 2;
264 }
265 
266 
267 /* True iff BYTE starts a non-ASCII character in a multibyte form.  */
268 INLINE bool
LEADING_CODE_P(int byte)269 LEADING_CODE_P (int byte)
270 {
271   return (byte & 0xC0) == 0xC0;
272 }
273 
274 /* True iff BYTE is a trailing code of a non-ASCII character in a
275    multibyte form.  */
276 INLINE bool
TRAILING_CODE_P(int byte)277 TRAILING_CODE_P (int byte)
278 {
279   return (byte & 0xC0) == 0x80;
280 }
281 
282 /* True iff BYTE starts a character in a multibyte form.
283    This is equivalent to:
284 	(ASCII_CHAR_P (byte) || LEADING_CODE_P (byte))  */
285 INLINE bool
CHAR_HEAD_P(int byte)286 CHAR_HEAD_P (int byte)
287 {
288   return (byte & 0xC0) != 0x80;
289 }
290 
291 /* How many bytes a character that starts with BYTE occupies in a
292    multibyte form.  Unlike multibyte_length, this function does not
293    validate the multibyte form, but looks only at its first byte.  */
294 INLINE int
BYTES_BY_CHAR_HEAD(int byte)295 BYTES_BY_CHAR_HEAD (int byte)
296 {
297   return (!(byte & 0x80) ? 1
298 	  : !(byte & 0x20) ? 2
299 	  : !(byte & 0x10) ? 3
300 	  : !(byte & 0x08) ? 4
301 	  : 5);
302 }
303 
304 
305 /* The byte length of the multibyte form at the unibyte string P,
306    ending at PEND if CHECK, and without a length check if !CHECK.
307    If ALLOW_8BIT, allow multibyte forms of eight-bit characters.
308    If the string doesn't point to a valid multibyte form, return 0.
309    Unlike BYTES_BY_CHAR_HEAD, this function validates the multibyte form.  */
310 
311 INLINE int
multibyte_length(unsigned char const * p,unsigned char const * pend,bool check,bool allow_8bit)312 multibyte_length (unsigned char const *p, unsigned char const *pend,
313 		  bool check, bool allow_8bit)
314 {
315   if (!check || p < pend)
316     {
317       unsigned char c = p[0];
318       if (c < 0x80)
319 	return 1;
320       if (!check || p + 1 < pend)
321 	{
322 	  unsigned char d = p[1];
323 	  int w = ((d & 0xC0) << 2) + c;
324 	  if ((allow_8bit ? 0x2C0 : 0x2C2) <= w && w <= 0x2DF)
325 	    return 2;
326 	  if (!check || p + 2 < pend)
327 	    {
328 	      unsigned char e = p[2];
329 	      w += (e & 0xC0) << 4;
330 	      int w1 = w | ((d & 0x20) >> 2);
331 	      if (0xAE1 <= w1 && w1 <= 0xAEF)
332 		return 3;
333 	      if (!check || p + 3 < pend)
334 		{
335 		  unsigned char f = p[3];
336 		  w += (f & 0xC0) << 6;
337 		  int w2 = w | ((d & 0x30) >> 3);
338 		  if (0x2AF1 <= w2 && w2 <= 0x2AF7)
339 		    return 4;
340 		  if (!check || p + 4 < pend)
341 		    {
342 		      int_fast64_t lw = w + ((p[4] & 0xC0) << 8),
343 			w3 = (lw << 24) + (d << 16) + (e << 8) + f;
344 		      if (0xAAF8888080 <= w3 && w3 <= 0xAAF88FBFBD)
345 			return 5;
346 		    }
347 		}
348 	    }
349 	}
350     }
351 
352   return 0;
353 }
354 
355 
356 /* Return number of bytes in the multibyte character just before P.
357    Assumes that P is already at a character boundary of the same
358    multibyte form, and is not at the start of that form.  */
359 
360 INLINE int
raw_prev_char_len(unsigned char const * p)361 raw_prev_char_len (unsigned char const *p)
362 {
363   for (int len = 1; ; len++)
364     if (CHAR_HEAD_P (p[-len]))
365       return len;
366 }
367 
368 
369 /* Return the character code of character whose multibyte form is at P,
370    and set *LENGTH to its length.  */
371 
372 INLINE int
string_char_and_length(unsigned char const * p,int * length)373 string_char_and_length (unsigned char const *p, int *length)
374 {
375   int c = p[0];
376   if (! (c & 0x80))
377     {
378       *length = 1;
379       return c;
380     }
381   eassume (0xC0 <= c);
382 
383   int d = (c << 6) + p[1] - ((0xC0 << 6) + 0x80);
384   if (! (c & 0x20))
385     {
386       *length = 2;
387       return d + (c < 0xC2 ? 0x3FFF80 : 0);
388     }
389 
390   d = (d << 6) + p[2] - ((0x20 << 12) + 0x80);
391   if (! (c & 0x10))
392     {
393       *length = 3;
394       eassume (MAX_2_BYTE_CHAR < d && d <= MAX_3_BYTE_CHAR);
395       return d;
396     }
397 
398   d = (d << 6) + p[3] - ((0x10 << 18) + 0x80);
399   if (! (c & 0x08))
400     {
401       *length = 4;
402       eassume (MAX_3_BYTE_CHAR < d && d <= MAX_4_BYTE_CHAR);
403       return d;
404     }
405 
406   d = (d << 6) + p[4] - ((0x08 << 24) + 0x80);
407   *length = 5;
408   eassume (MAX_4_BYTE_CHAR < d && d <= MAX_5_BYTE_CHAR);
409   return d;
410 }
411 
412 /* Return the character code of character whose multibyte form is at P.  */
413 
414 INLINE int
STRING_CHAR(unsigned char const * p)415 STRING_CHAR (unsigned char const *p)
416 {
417   int len;
418   return string_char_and_length (p, &len);
419 }
420 
421 
422 /* Like STRING_CHAR (*PP), but advance *PP to the end of multibyte form.  */
423 
424 INLINE int
string_char_advance(unsigned char const ** pp)425 string_char_advance (unsigned char const **pp)
426 {
427   unsigned char const *p = *pp;
428   int len, c = string_char_and_length (p, &len);
429   *pp = p + len;
430   return c;
431 }
432 
433 
434 /* Return the next character from Lisp string STRING at byte position
435    *BYTEIDX, character position *CHARIDX.  Update *BYTEIDX and
436    *CHARIDX past the character fetched.  */
437 
438 INLINE int
fetch_string_char_advance(Lisp_Object string,ptrdiff_t * charidx,ptrdiff_t * byteidx)439 fetch_string_char_advance (Lisp_Object string,
440 			   ptrdiff_t *charidx, ptrdiff_t *byteidx)
441 {
442   int output;
443   ptrdiff_t b = *byteidx;
444   unsigned char *chp = SDATA (string) + b;
445   if (STRING_MULTIBYTE (string))
446     {
447       int chlen;
448       output = string_char_and_length (chp, &chlen);
449       b += chlen;
450     }
451   else
452     {
453       output = *chp;
454       b++;
455     }
456   (*charidx)++;
457   *byteidx = b;
458   return output;
459 }
460 
461 /* Like fetch_string_char_advance, but return a multibyte character
462    even if STRING is unibyte.  */
463 
464 INLINE int
fetch_string_char_as_multibyte_advance(Lisp_Object string,ptrdiff_t * charidx,ptrdiff_t * byteidx)465 fetch_string_char_as_multibyte_advance (Lisp_Object string,
466 					ptrdiff_t *charidx, ptrdiff_t *byteidx)
467 {
468   int output;
469   ptrdiff_t b = *byteidx;
470   unsigned char *chp = SDATA (string) + b;
471   if (STRING_MULTIBYTE (string))
472     {
473       int chlen;
474       output = string_char_and_length (chp, &chlen);
475       b += chlen;
476     }
477   else
478     {
479       output = make_char_multibyte (*chp);
480       b++;
481     }
482   (*charidx)++;
483   *byteidx = b;
484   return output;
485 }
486 
487 
488 /* Like fetch_string_char_advance, but assumes STRING is multibyte.  */
489 
490 INLINE int
fetch_string_char_advance_no_check(Lisp_Object string,ptrdiff_t * charidx,ptrdiff_t * byteidx)491 fetch_string_char_advance_no_check (Lisp_Object string,
492 				    ptrdiff_t *charidx, ptrdiff_t *byteidx)
493 {
494   ptrdiff_t b = *byteidx;
495   unsigned char *chp = SDATA (string) + b;
496   int chlen, output = string_char_and_length (chp, &chlen);
497   (*charidx)++;
498   *byteidx = b + chlen;
499   return output;
500 }
501 
502 
503 /* If C is a variation selector, return the index of the
504    variation selector (1..256).  Otherwise, return 0.  */
505 
506 INLINE int
CHAR_VARIATION_SELECTOR_P(int c)507 CHAR_VARIATION_SELECTOR_P (int c)
508 {
509   return (c < 0xFE00 ? 0
510 	  : c <= 0xFE0F ? c - 0xFE00 + 1
511 	  : c < 0xE0100 ? 0
512 	  : c <= 0xE01EF ? c - 0xE0100 + 17
513 	  : 0);
514 }
515 
516 /* Return true if C is a surrogate.  */
517 
518 INLINE bool
char_surrogate_p(int c)519 char_surrogate_p (int c)
520 {
521   return 0xD800 <= c && c <= 0xDFFF;
522 }
523 
524 /* Data type for Unicode general category.
525 
526    The order of members must be in sync with the 8th element of the
527    member of unidata-prop-alist (in admin/unidata/unidata-gen.el) for
528    Unicode character property `general-category'.  */
529 
530 typedef enum {
531   UNICODE_CATEGORY_UNKNOWN = 0,
532   UNICODE_CATEGORY_Lu,
533   UNICODE_CATEGORY_Ll,
534   UNICODE_CATEGORY_Lt,
535   UNICODE_CATEGORY_Lm,
536   UNICODE_CATEGORY_Lo,
537   UNICODE_CATEGORY_Mn,
538   UNICODE_CATEGORY_Mc,
539   UNICODE_CATEGORY_Me,
540   UNICODE_CATEGORY_Nd,
541   UNICODE_CATEGORY_Nl,
542   UNICODE_CATEGORY_No,
543   UNICODE_CATEGORY_Pc,
544   UNICODE_CATEGORY_Pd,
545   UNICODE_CATEGORY_Ps,
546   UNICODE_CATEGORY_Pe,
547   UNICODE_CATEGORY_Pi,
548   UNICODE_CATEGORY_Pf,
549   UNICODE_CATEGORY_Po,
550   UNICODE_CATEGORY_Sm,
551   UNICODE_CATEGORY_Sc,
552   UNICODE_CATEGORY_Sk,
553   UNICODE_CATEGORY_So,
554   UNICODE_CATEGORY_Zs,
555   UNICODE_CATEGORY_Zl,
556   UNICODE_CATEGORY_Zp,
557   UNICODE_CATEGORY_Cc,
558   UNICODE_CATEGORY_Cf,
559   UNICODE_CATEGORY_Cs,
560   UNICODE_CATEGORY_Co,
561   UNICODE_CATEGORY_Cn
562 } unicode_category_t;
563 
564 extern EMACS_INT char_resolve_modifier_mask (EMACS_INT) ATTRIBUTE_CONST;
565 
566 extern int translate_char (Lisp_Object, int c);
567 extern ptrdiff_t count_size_as_multibyte (const unsigned char *, ptrdiff_t);
568 extern ptrdiff_t str_as_multibyte (unsigned char *, ptrdiff_t, ptrdiff_t,
569 				   ptrdiff_t *);
570 extern ptrdiff_t str_to_multibyte (unsigned char *, ptrdiff_t, ptrdiff_t);
571 extern ptrdiff_t str_as_unibyte (unsigned char *, ptrdiff_t);
572 extern ptrdiff_t str_to_unibyte (const unsigned char *, unsigned char *,
573                                  ptrdiff_t);
574 extern ptrdiff_t strwidth (const char *, ptrdiff_t);
575 extern ptrdiff_t c_string_width (const unsigned char *, ptrdiff_t, int,
576 				 ptrdiff_t *, ptrdiff_t *);
577 extern ptrdiff_t lisp_string_width (Lisp_Object, ptrdiff_t, ptrdiff_t,
578 				    ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
579 
580 extern Lisp_Object Vchar_unify_table;
581 extern Lisp_Object string_escape_byte8 (Lisp_Object);
582 
583 extern bool alphabeticp (int);
584 extern bool alphanumericp (int);
585 extern bool graphicp (int);
586 extern bool printablep (int);
587 extern bool blankp (int);
588 extern bool graphic_base_p (int);
589 
590 /* Look up the element in char table OBJ at index CH, and return it as
591    an integer.  If the element is not a character, return CH itself.  */
592 
593 INLINE int
char_table_translate(Lisp_Object obj,int ch)594 char_table_translate (Lisp_Object obj, int ch)
595 {
596   /* This internal function is expected to be called with valid arguments,
597      so there is an eassert instead of CHECK_xxx for the sake of speed.  */
598   eassert (CHAR_VALID_P (ch));
599   eassert (CHAR_TABLE_P (obj));
600   obj = CHAR_TABLE_REF (obj, ch);
601   return CHARACTERP (obj) ? XFIXNUM (obj) : ch;
602 }
603 
604 extern signed char const hexdigit[];
605 
606 /* If C is a hexadecimal digit ('0'-'9', 'a'-'f', 'A'-'F'), return its
607    value (0-15).  Otherwise return -1.  */
608 
609 INLINE int
char_hexdigit(int c)610 char_hexdigit (int c)
611 {
612   return 0 <= c && c <= UCHAR_MAX ? hexdigit[c] - 1 : -1;
613 }
614 
615 INLINE_HEADER_END
616 
617 #endif /* EMACS_CHARACTER_H */
618