2009-02-19 20:18:25 +03:00
|
|
|
/*
|
2011-07-15 16:50:29 +04:00
|
|
|
** $Id: lctype.h,v 1.11 2011/06/27 18:22:46 roberto Exp roberto $
|
2009-02-19 20:18:25 +03:00
|
|
|
** 'ctype' functions for Lua
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lctype_h
|
|
|
|
#define lctype_h
|
|
|
|
|
2011-06-24 16:25:33 +04:00
|
|
|
#include "lua.h"
|
|
|
|
|
2009-02-19 20:18:25 +03:00
|
|
|
|
2011-06-23 20:01:06 +04:00
|
|
|
/*
|
2011-07-15 16:50:29 +04:00
|
|
|
** WARNING: the functions defined here do not necessarily correspond
|
2011-06-23 20:01:06 +04:00
|
|
|
** to the similar functions in the standard C ctype.h. They are
|
|
|
|
** optimized for the specific needs of Lua
|
|
|
|
*/
|
|
|
|
|
2011-06-24 16:25:33 +04:00
|
|
|
#if !defined(LUA_USE_CTYPE)
|
2011-06-23 20:01:06 +04:00
|
|
|
|
2011-06-24 16:25:33 +04:00
|
|
|
#if 'A' == 65 && '0' == 48
|
|
|
|
/* ASCII case: can use its own tables; faster and fixed */
|
|
|
|
#define LUA_USE_CTYPE 0
|
|
|
|
#else
|
|
|
|
/* must use standard C ctype */
|
|
|
|
#define LUA_USE_CTYPE 1
|
|
|
|
#endif
|
2009-02-19 20:18:25 +03:00
|
|
|
|
2011-06-24 16:25:33 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if !LUA_USE_CTYPE /* { */
|
|
|
|
|
|
|
|
#include <limits.h>
|
2009-02-19 20:18:25 +03:00
|
|
|
|
2009-05-27 20:51:15 +04:00
|
|
|
#include "llimits.h"
|
|
|
|
|
2009-02-19 20:18:25 +03:00
|
|
|
|
|
|
|
#define ALPHABIT 0
|
|
|
|
#define DIGITBIT 1
|
|
|
|
#define PRINTBIT 2
|
|
|
|
#define SPACEBIT 3
|
2009-03-10 20:42:33 +03:00
|
|
|
#define XDIGITBIT 4
|
2009-02-19 20:18:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define MASK(B) (1 << (B))
|
|
|
|
|
|
|
|
|
2009-03-26 21:53:52 +03:00
|
|
|
/*
|
|
|
|
** add 1 to char to allow index -1 (EOZ)
|
|
|
|
*/
|
|
|
|
#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
|
|
|
|
|
|
|
|
/*
|
|
|
|
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
|
|
|
|
*/
|
|
|
|
#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))
|
|
|
|
|
2011-06-23 20:01:06 +04:00
|
|
|
/*
|
2011-06-24 16:25:33 +04:00
|
|
|
** this 'ltolower' only works for alphabetic characters
|
2011-06-23 20:01:06 +04:00
|
|
|
*/
|
2011-06-27 22:22:46 +04:00
|
|
|
#define ltolower(c) ((c) | ('A' ^ 'a'))
|
2011-06-23 20:01:06 +04:00
|
|
|
|
2009-02-19 20:18:25 +03:00
|
|
|
|
2011-06-24 16:25:33 +04:00
|
|
|
/* two more entries for 0 and -1 (EOZ) */
|
2009-11-19 22:06:52 +03:00
|
|
|
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
|
2009-02-19 20:18:25 +03:00
|
|
|
|
2011-06-24 16:25:33 +04:00
|
|
|
|
|
|
|
#else /* }{ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
** use standard C ctypes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
|
|
|
|
#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))
|
|
|
|
|
|
|
|
#define ltolower(c) (tolower(c))
|
|
|
|
|
|
|
|
#endif /* } */
|
|
|
|
|
2009-02-19 20:18:25 +03:00
|
|
|
#endif
|
|
|
|
|