lctype.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. ** $Id: lctype.h,v 1.7 2009/05/27 16:51:15 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. #include "llimits.h"
  11. #define ALPHABIT 0
  12. #define DIGITBIT 1
  13. #define PRINTBIT 2
  14. #define SPACEBIT 3
  15. #define XDIGITBIT 4
  16. #define UPPERBIT 5
  17. #define MASK(B) (1 << (B))
  18. /*
  19. ** add 1 to char to allow index -1 (EOZ)
  20. */
  21. #define testprop(c,p) (luai_ctype_[(c)+1] & (p))
  22. /*
  23. ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
  24. */
  25. #define lislalpha(c) testprop(c, MASK(ALPHABIT))
  26. #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
  27. #define lisupper(c) testprop(c, MASK(UPPERBIT))
  28. #define lisdigit(c) testprop(c, MASK(DIGITBIT))
  29. #define lisspace(c) testprop(c, MASK(SPACEBIT))
  30. #define lisprint(c) testprop(c, MASK(PRINTBIT))
  31. #define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
  32. /* one more entry for 0 and one more for -1 (EOZ) */
  33. LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
  34. #endif