sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
lctype.h
Go to the documentation of this file.
1/*
2** $Id: lctype.h $
3** 'ctype' functions for Lua
4** See Copyright Notice in lua.h
5*/
6
11#ifndef lctype_h
12#define lctype_h
13
14#include "lua.h"
15
16
17/*
18** WARNING: the functions defined here do not necessarily correspond
19** to the similar functions in the standard C ctype.h. They are
20** optimized for the specific needs of Lua.
21*/
22
23#if !defined(LUA_USE_CTYPE)
24
25#if 'A' == 65 && '0' == 48
26/* ASCII case: can use its own tables; faster and fixed */
27#define LUA_USE_CTYPE 0
28#else
29/* must use standard C ctype */
30#define LUA_USE_CTYPE 1
31#endif
32
33#endif
34
35
36#if !LUA_USE_CTYPE /* { */
37
38#include <limits.h>
39
40#include "llimits.h"
41
42
43#define ALPHABIT 0
44#define DIGITBIT 1
45#define PRINTBIT 2
46#define SPACEBIT 3
47#define XDIGITBIT 4
48
49
50#define MASK(B) (1 << (B))
51
52
53/*
54** add 1 to char to allow index -1 (EOZ)
55*/
56#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
57
58/*
59** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
60*/
61#define lislalpha(c) testprop(c, MASK(ALPHABIT))
62#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
63#define lisdigit(c) testprop(c, MASK(DIGITBIT))
64#define lisspace(c) testprop(c, MASK(SPACEBIT))
65#define lisprint(c) testprop(c, MASK(PRINTBIT))
66#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
67
68
69/*
70** In ASCII, this 'ltolower' is correct for alphabetic characters and
71** for '.'. That is enough for Lua needs. ('check_exp' ensures that
72** the character either is an upper-case letter or is unchanged by
73** the transformation, which holds for lower-case letters and '.'.)
74*/
75#define ltolower(c) \
76 check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \
77 (c) | ('A' ^ 'a'))
78
79
80/* one entry for each character and for -1 (EOZ) */
81LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];)
82
83
84#else /* }{ */
85
86/*
87** use standard C ctypes
88*/
89
90#include <ctype.h>
91
92
93#define lislalpha(c) (isalpha(c) || (c) == '_')
94#define lislalnum(c) (isalnum(c) || (c) == '_')
95#define lisdigit(c) (isdigit(c))
96#define lisspace(c) (isspace(c))
97#define lisprint(c) (isprint(c))
98#define lisxdigit(c) (isxdigit(c))
99
100#define ltolower(c) (tolower(c))
101
102#endif /* } */
103
104#endif
105