The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lctype.h
Go to the documentation of this file.
1 /*
2 ** 'ctype' functions for Lua
3 ** See Copyright Notice in lua.h
4 */
5 
6 #ifndef lctype_h
7 #define lctype_h
8 
9 #include "lua.h"
10 
11 
12 /*
13 ** WARNING: the functions defined here do not necessarily correspond
14 ** to the similar functions in the standard C ctype.h. They are
15 ** optimized for the specific needs of Lua
16 */
17 
18 #if !defined(LUA_USE_CTYPE)
19 
20 #if 'A' == 65 && '0' == 48
21 /* ASCII case: can use its own tables; faster and fixed */
22 #define LUA_USE_CTYPE 0
23 #else
24 /* must use standard C ctype */
25 #define LUA_USE_CTYPE 1
26 #endif
27 
28 #endif
29 
30 
31 #if !LUA_USE_CTYPE /* { */
32 
33 #include <limits.h>
34 
35 #include "llimits.h"
36 
37 
38 #define ALPHABIT 0
39 #define DIGITBIT 1
40 #define PRINTBIT 2
41 #define SPACEBIT 3
42 #define XDIGITBIT 4
43 
44 
45 #define MASK(B) (1 << (B))
46 
47 
48 /*
49 ** add 1 to char to allow index -1 (EOZ)
50 */
51 #define testprop(c,p) (luai_ctype_[(c)+1] & (p))
52 
53 /*
54 ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
55 */
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))
62 
63 /*
64 ** this 'ltolower' only works for alphabetic characters
65 */
66 #define ltolower(c) ((c) | ('A' ^ 'a'))
67 
68 
69 /* two more entries for 0 and -1 (EOZ) */
70 LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
71 
72 
73 #else /* }{ */
74 
75 /*
76 ** use standard C ctypes
77 */
78 
79 #include <ctype.h>
80 
81 
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))
88 
89 #define ltolower(c) (tolower(c))
90 
91 #endif /* } */
92 
93 #endif
94 
#define LUAI_DDEC
Definition: luaconf.h:188
unsigned char lu_byte
Definition: llimits.h:26