1323530Savg/*
2323530Savg** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $
3323530Savg** 'ctype' functions for Lua
4323530Savg** See Copyright Notice in lua.h
5323530Savg*/
6323530Savg
7323530Savg#ifndef lctype_h
8323530Savg#define lctype_h
9323530Savg
10323530Savg#include "lua.h"
11323530Savg
12323530Savg
13323530Savg/*
14323530Savg** WARNING: the functions defined here do not necessarily correspond
15323530Savg** to the similar functions in the standard C ctype.h. They are
16323530Savg** optimized for the specific needs of Lua
17323530Savg*/
18323530Savg
19323530Savg#if !defined(LUA_USE_CTYPE)
20323530Savg
21323530Savg#if 'A' == 65 && '0' == 48
22323530Savg/* ASCII case: can use its own tables; faster and fixed */
23323530Savg#define LUA_USE_CTYPE	0
24323530Savg#else
25323530Savg/* must use standard C ctype */
26323530Savg#define LUA_USE_CTYPE	1
27323530Savg#endif
28323530Savg
29323530Savg#endif
30323530Savg
31323530Savg
32323530Savg#if !LUA_USE_CTYPE	/* { */
33323530Savg
34323530Savg#include "llimits.h"
35323530Savg
36323530Savg
37323530Savg#define ALPHABIT	0
38323530Savg#define DIGITBIT	1
39323530Savg#define PRINTBIT	2
40323530Savg#define SPACEBIT	3
41323530Savg#define XDIGITBIT	4
42323530Savg
43323530Savg
44323530Savg#define MASK(B)		(1 << (B))
45323530Savg
46323530Savg
47323530Savg/*
48323530Savg** add 1 to char to allow index -1 (EOZ)
49323530Savg*/
50323530Savg#define testprop(c,p)	(luai_ctype_[(c)+1] & (p))
51323530Savg
52323530Savg/*
53323530Savg** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
54323530Savg*/
55323530Savg#define lislalpha(c)	testprop(c, MASK(ALPHABIT))
56323530Savg#define lislalnum(c)	testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
57323530Savg#define lisdigit(c)	testprop(c, MASK(DIGITBIT))
58323530Savg#define lisspace(c)	testprop(c, MASK(SPACEBIT))
59323530Savg#define lisprint(c)	testprop(c, MASK(PRINTBIT))
60323530Savg#define lisxdigit(c)	testprop(c, MASK(XDIGITBIT))
61323530Savg
62323530Savg/*
63323530Savg** this 'ltolower' only works for alphabetic characters
64323530Savg*/
65323530Savg#define ltolower(c)	((c) | ('A' ^ 'a'))
66323530Savg
67323530Savg
68323530Savg/* two more entries for 0 and -1 (EOZ) */
69323530SavgLUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
70323530Savg
71323530Savg
72323530Savg#else			/* }{ */
73323530Savg
74323530Savg/*
75323530Savg** use standard C ctypes
76323530Savg*/
77323530Savg
78323530Savg#include <ctype.h>
79323530Savg
80323530Savg
81323530Savg#define lislalpha(c)	(isalpha(c) || (c) == '_')
82323530Savg#define lislalnum(c)	(isalnum(c) || (c) == '_')
83323530Savg#define lisdigit(c)	(isdigit(c))
84323530Savg#define lisspace(c)	(isspace(c))
85323530Savg#define lisprint(c)	(isprint(c))
86323530Savg#define lisxdigit(c)	(isxdigit(c))
87323530Savg
88323530Savg#define ltolower(c)	(tolower(c))
89323530Savg
90323530Savg#endif			/* } */
91323530Savg
92323530Savg#endif
93323530Savg
94