summaryrefslogtreecommitdiff
path: root/src/lj_char.h
diff options
context:
space:
mode:
authorMike Pall <mike>2010-11-09 12:09:54 +0100
committerMike Pall <mike>2010-11-09 12:09:54 +0100
commitad29c1f39feb55d4d443b9352448a12a1be8ee23 (patch)
tree685adbbcad3f65cacf636dda30bf1785191d9c6e /src/lj_char.h
parentfe21a42a92546416cc235511c4e1949d850c0139 (diff)
downloadluajit2-ad29c1f39feb55d4d443b9352448a12a1be8ee23.tar.gz
Rename character type handling from lj_ctype* to lj_char*.
Diffstat (limited to 'src/lj_char.h')
-rw-r--r--src/lj_char.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lj_char.h b/src/lj_char.h
new file mode 100644
index 00000000..d474285c
--- /dev/null
+++ b/src/lj_char.h
@@ -0,0 +1,40 @@
+/*
+** Character types.
+** Donated to the public domain.
+*/
+
+#ifndef _LJ_CHAR_H
+#define _LJ_CHAR_H
+
+#include "lj_def.h"
+
+#define LJ_CHAR_CNTRL 0x01
+#define LJ_CHAR_SPACE 0x02
+#define LJ_CHAR_PUNCT 0x04
+#define LJ_CHAR_DIGIT 0x08
+#define LJ_CHAR_XDIGIT 0x10
+#define LJ_CHAR_UPPER 0x20
+#define LJ_CHAR_LOWER 0x40
+#define LJ_CHAR_IDENT 0x80
+#define LJ_CHAR_ALPHA (LJ_CHAR_LOWER|LJ_CHAR_UPPER)
+#define LJ_CHAR_ALNUM (LJ_CHAR_ALPHA|LJ_CHAR_DIGIT)
+
+/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */
+#define lj_char_isa(c, t) (lj_char_bits[(c)+1] & t)
+#define lj_char_iscntrl(c) lj_char_isa((c), LJ_CHAR_CNTRL)
+#define lj_char_isspace(c) lj_char_isa((c), LJ_CHAR_SPACE)
+#define lj_char_ispunct(c) lj_char_isa((c), LJ_CHAR_PUNCT)
+#define lj_char_isdigit(c) lj_char_isa((c), LJ_CHAR_DIGIT)
+#define lj_char_isxdigit(c) lj_char_isa((c), LJ_CHAR_XDIGIT)
+#define lj_char_isupper(c) lj_char_isa((c), LJ_CHAR_UPPER)
+#define lj_char_islower(c) lj_char_isa((c), LJ_CHAR_LOWER)
+#define lj_char_isident(c) lj_char_isa((c), LJ_CHAR_IDENT)
+#define lj_char_isalpha(c) lj_char_isa((c), LJ_CHAR_ALPHA)
+#define lj_char_isalnum(c) lj_char_isa((c), LJ_CHAR_ALNUM)
+
+#define lj_char_toupper(c) ((c) - (lj_char_islower(c) >> 1))
+#define lj_char_tolower(c) ((c) + lj_char_isupper(c))
+
+LJ_DATA const uint8_t lj_char_bits[257];
+
+#endif