2013-05-22 02:23:42 +08:00
|
|
|
/*
|
|
|
|
** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $
|
|
|
|
** 'ctype' functions for Lua
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lctype_h
|
|
|
|
#define lctype_h
|
|
|
|
|
|
|
|
#include "lua.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** WARNING: the functions defined here do not necessarily correspond
|
|
|
|
** to the similar functions in the standard C ctype.h. They are
|
|
|
|
** optimized for the specific needs of Lua
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(LUA_USE_CTYPE)
|
|
|
|
|
|
|
|
#if 'A' == 65 && '0' == 48
|
|
|
|
/* ASCII case: can use its own tables; faster and fixed */
|
2019-03-10 01:16:50 +08:00
|
|
|
#define LUA_USE_CTYPE 0
|
2013-05-22 02:23:42 +08:00
|
|
|
#else
|
|
|
|
/* must use standard C ctype */
|
2019-03-10 01:16:50 +08:00
|
|
|
#define LUA_USE_CTYPE 1
|
2013-05-22 02:23:42 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2019-03-10 01:16:50 +08:00
|
|
|
#if !LUA_USE_CTYPE /* { */
|
2013-05-22 02:23:42 +08:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "llimits.h"
|
|
|
|
|
|
|
|
|
2019-03-10 01:16:50 +08:00
|
|
|
#define ALPHABIT 0
|
|
|
|
#define DIGITBIT 1
|
|
|
|
#define PRINTBIT 2
|
|
|
|
#define SPACEBIT 3
|
|
|
|
#define XDIGITBIT 4
|
2013-05-22 02:23:42 +08:00
|
|
|
|
|
|
|
|
2019-03-10 01:16:50 +08:00
|
|
|
#define MASK(B) (1 << (B))
|
2013-05-22 02:23:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** add 1 to char to allow index -1 (EOZ)
|
|
|
|
*/
|
2019-03-10 01:16:50 +08:00
|
|
|
#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
|
2013-05-22 02:23:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
|
|
|
|
*/
|
2019-03-10 01:16:50 +08:00
|
|
|
#define lislalpha(c) testprop(c, MASK(ALPHABIT))
|
|
|
|
#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
|
|
|
|
#define lisdigit(c) testprop(c, MASK(DIGITBIT))
|
|
|
|
#define lisspace(c) testprop(c, MASK(SPACEBIT))
|
|
|
|
#define lisprint(c) testprop(c, MASK(PRINTBIT))
|
|
|
|
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
|
2013-05-22 02:23:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** this 'ltolower' only works for alphabetic characters
|
|
|
|
*/
|
2019-03-10 01:16:50 +08:00
|
|
|
#define ltolower(c) ((c) | ('A' ^ 'a'))
|
2013-05-22 02:23:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* two more entries for 0 and -1 (EOZ) */
|
|
|
|
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
|
|
|
|
|
|
|
|
|
2019-03-10 01:16:50 +08:00
|
|
|
#else /* }{ */
|
2013-05-22 02:23:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** use standard C ctypes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
|
2019-03-10 01:16:50 +08:00
|
|
|
#define lislalpha(c) (isalpha(c) || (c) == '_')
|
|
|
|
#define lislalnum(c) (isalnum(c) || (c) == '_')
|
|
|
|
#define lisdigit(c) (isdigit(c))
|
|
|
|
#define lisspace(c) (isspace(c))
|
|
|
|
#define lisprint(c) (isprint(c))
|
|
|
|
#define lisxdigit(c) (isxdigit(c))
|
2013-05-22 02:23:42 +08:00
|
|
|
|
2019-03-10 01:16:50 +08:00
|
|
|
#define ltolower(c) (tolower(c))
|
2013-05-22 02:23:42 +08:00
|
|
|
|
2019-03-10 01:16:50 +08:00
|
|
|
#endif /* } */
|
2013-05-22 02:23:42 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|