3 ** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $
4 ** 'ctype' functions for Lua
5 ** See Copyright Notice in lua.h
11 #include <sys/lua/lua.h>
15 ** WARNING: the functions defined here do not necessarily correspond
16 ** to the similar functions in the standard C ctype.h. They are
17 ** optimized for the specific needs of Lua
20 #if !defined(LUA_USE_CTYPE)
22 #if 'A' == 65 && '0' == 48
23 /* ASCII case: can use its own tables; faster and fixed */
24 #define LUA_USE_CTYPE 0
26 /* must use standard C ctype */
27 #define LUA_USE_CTYPE 1
33 #if !LUA_USE_CTYPE /* { */
45 #define MASK(B) (1 << (B))
49 ** add 1 to char to allow index -1 (EOZ)
51 #define testprop(c,p) (luai_ctype_[(lu_byte)(c)+1] & (p))
54 ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
56 #define lislalpha(c) testprop(c, MASK(ALPHABIT))
57 #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
58 #define lisdigit(c) testprop(c, MASK(DIGITBIT))
59 #define lisspace(c) testprop(c, MASK(SPACEBIT))
60 #define lisprint(c) testprop(c, MASK(PRINTBIT))
61 #define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
64 ** this 'ltolower' only works for alphabetic characters
66 #define ltolower(c) ((c) | ('A' ^ 'a'))
69 /* two more entries for 0 and -1 (EOZ) */
70 LUAI_DDEC
const lu_byte luai_ctype_
[UCHAR_MAX
+ 2];
76 ** use standard C ctypes
82 #define lislalpha(c) (isalpha(c) || (c) == '_')
83 #define lislalnum(c) (isalnum(c) || (c) == '_')
84 #define lisdigit(c) (isdigit(c))
85 #define lisspace(c) (isspace(c))
86 #define lisprint(c) (isprint(c))
87 #define lisxdigit(c) (isxdigit(c))
89 #define ltolower(c) (tolower(c))