lctype.h 943 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. ** $Id: lctype.h,v 1.4 2009/03/11 13:27:32 roberto Exp roberto $
  3. ** 'ctype' functions for Lua
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lctype_h
  7. #define lctype_h
  8. #include <limits.h>
  9. #include "lua.h"
  10. #define ALPHABIT 0
  11. #define DIGITBIT 1
  12. #define PRINTBIT 2
  13. #define SPACEBIT 3
  14. #define XDIGITBIT 4
  15. #define MASK(B) (1 << (B))
  16. /*
  17. ** add 1 to char to allow index -1 (EOZ)
  18. */
  19. #define testprop(c,p) (luai_ctype_[(c)+1] & (p))
  20. /*
  21. ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
  22. */
  23. #define lislalpha(c) testprop(c, MASK(ALPHABIT))
  24. #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
  25. #define lisdigit(c) testprop(c, MASK(DIGITBIT))
  26. #define lisspace(c) testprop(c, MASK(SPACEBIT))
  27. #define lisprint(c) testprop(c, MASK(PRINTBIT))
  28. #define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
  29. /* one more entry for 0 and one more for -1 (EOZ) */
  30. LUAI_DATA const char luai_ctype_[UCHAR_MAX + 2];
  31. #endif