return XINT (category) == UNICODE_CATEGORY_Zs; /* separator, space */
}
+signed char HEXDIGIT_CONST hexdigit[UCHAR_MAX + 1] =
+ {
+#if HEXDIGIT_IS_CONST
+ [0 ... UCHAR_MAX] = -1,
+#endif
+ ['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3, ['4'] = 4,
+ ['5'] = 5, ['6'] = 6, ['7'] = 7, ['8'] = 8, ['9'] = 9,
+ ['A'] = 10, ['B'] = 11, ['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15,
+ ['a'] = 10, ['b'] = 11, ['c'] = 12, ['d'] = 13, ['e'] = 14, ['f'] = 15
+ };
+
void
syms_of_character (void)
{
+#if !HEXDIGIT_IS_CONST
+ /* Set the non-hex digit values to -1. */
+ for (int i = 0; i <= UCHAR_MAX; i++)
+ hexdigit[i] -= i != '0' && !hexdigit[i];
+#endif
+
DEFSYM (Qcharacterp, "characterp");
DEFSYM (Qauto_fill_chars, "auto-fill-chars");
return CHARACTERP (obj) ? XINT (obj) : ch;
}
+#if defined __GNUC__ && !defined __STRICT_ANSI__
+# define HEXDIGIT_CONST const
+# define HEXDIGIT_IS_CONST true
+#else
+# define HEXDIGIT_CONST
+# define HEXDIGIT_IS_CONST false
+#endif
+extern signed char HEXDIGIT_CONST hexdigit[];
+
+/* If C is a hexadecimal digit ('0'-'9', 'a'-'f', 'A'-'F'), return its
+ value (0-15). Otherwise return -1. */
+
+INLINE int
+char_hexdigit (int c)
+{
+ return 0 <= c && c <= UCHAR_MAX ? hexdigit[c] : -1;
+}
+
INLINE_HEADER_END
#endif /* EMACS_CHARACTER_H */
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
-#include <c-ctype.h>
#include "lisp.h"
#include "character.h"
#include "charset.h"
return 0;
}
n = 0;
- while (c_isxdigit (c = getc_unlocked (fp)))
+ while (true)
{
+ c = getc_unlocked (fp);
+ int digit = char_hexdigit (c);
+ if (digit < 0)
+ break;
if (INT_LEFT_SHIFT_OVERFLOW (n, 4))
*overflow = 1;
- n = ((n << 4)
- | (c - ('0' <= c && c <= '9' ? '0'
- : 'A' <= c && c <= 'F' ? 'A' - 10
- : 'a' - 10)));
+ n = (n << 4) + digit;
}
if (c != EOF)
ungetc (c, fp);
char src0 = src[0];
int exponent_bytes = 0;
bool signedp = src0 == '-' || src0 == '+' || src0 == ' ';
- if (zero_flag
- && ((src[signedp] >= '0' && src[signedp] <= '9')
- || (src[signedp] >= 'a' && src[signedp] <= 'f')
- || (src[signedp] >= 'A' && src[signedp] <= 'F')))
+ unsigned char after_sign = src[signedp];
+ if (zero_flag && 0 <= char_hexdigit (after_sign))
{
leading_zeros += padding;
padding = 0;
while (*s < end)
{
c = *(*s)++;
- if (c_isdigit (c))
- digit = c - '0';
- else if (c >= 'a' && c <= 'f')
- digit = c - 'a' + 10;
- else if (c >= 'A' && c <= 'F')
- digit = c - 'A' + 10;
- else
+ digit = char_hexdigit (c);
+ if (digit < 0)
break;
value = 16 * value + digit;
}
while (1)
{
c = READCHAR;
- if (c >= '0' && c <= '9')
- {
- i *= 16;
- i += c - '0';
- }
- else if ((c >= 'a' && c <= 'f')
- || (c >= 'A' && c <= 'F'))
- {
- i *= 16;
- if (c >= 'a' && c <= 'f')
- i += c - 'a' + 10;
- else
- i += c - 'A' + 10;
- }
- else
+ int digit = char_hexdigit (c);
+ if (digit < 0)
{
UNREAD (c);
break;
}
+ i = (i << 4) + digit;
/* Allow hex escapes as large as ?\xfffffff, because some
packages use them to denote characters with modifiers. */
if ((CHAR_META | (CHAR_META - 1)) < i)
c = READCHAR;
/* `isdigit' and `isalpha' may be locale-specific, which we don't
want. */
- if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
- else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
- else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
- else
+ int digit = char_hexdigit (c);
+ if (digit < 0)
error ("Non-hex digit used for Unicode escape");
+ i = (i << 4) + digit;
}
if (i > 0x10FFFF)
error ("Non-Unicode character: 0x%x", i);
/* In Emacs, these are only used for single-byte characters. */
# define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
# define ISCNTRL(c) ((c) < ' ')
-# define ISXDIGIT(c) (((c) >= '0' && (c) <= '9') \
- || ((c) >= 'a' && (c) <= 'f') \
- || ((c) >= 'A' && (c) <= 'F'))
+# define ISXDIGIT(c) (0 <= char_hexdigit (c))
/* The rest must handle multibyte characters. */