2009-02-20 01:18:25 +08:00
|
|
|
/*
|
2011-06-24 00:01:06 +08:00
|
|
|
** $Id: lctype.h,v 1.8 2009/11/19 19:06:52 roberto Exp roberto $
|
2009-02-20 01:18:25 +08:00
|
|
|
** 'ctype' functions for Lua
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lctype_h
|
|
|
|
#define lctype_h
|
|
|
|
|
|
|
|
|
2011-06-24 00:01:06 +08:00
|
|
|
/*
|
|
|
|
** 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-02-20 01:18:25 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "lua.h"
|
|
|
|
|
2009-05-28 00:51:15 +08:00
|
|
|
#include "llimits.h"
|
|
|
|
|
2009-02-20 01:18:25 +08:00
|
|
|
|
|
|
|
#define ALPHABIT 0
|
|
|
|
#define DIGITBIT 1
|
|
|
|
#define PRINTBIT 2
|
|
|
|
#define SPACEBIT 3
|
2009-03-11 01:42:33 +08:00
|
|
|
#define XDIGITBIT 4
|
2009-02-20 01:18:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define MASK(B) (1 << (B))
|
|
|
|
|
|
|
|
|
2009-03-27 02:53:52 +08: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-24 00:01:06 +08:00
|
|
|
/*
|
|
|
|
** this 'ltoupper' only works for alphabetic characters
|
|
|
|
*/
|
|
|
|
#define ltoupper(c) ((c) & ~32)
|
|
|
|
|
2009-02-20 01:18:25 +08:00
|
|
|
|
2009-03-27 02:53:52 +08:00
|
|
|
/* one more entry for 0 and one more for -1 (EOZ) */
|
2009-11-20 03:06:52 +08:00
|
|
|
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
|
2009-02-20 01:18:25 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|