lctype.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. ** $Id: lctype.h,v 1.8 2009/11/19 19:06:52 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. /*
  9. ** WARNING: the functions defined here do not necessarily correspond
  10. ** to the similar functions in the standard C ctype.h. They are
  11. ** optimized for the specific needs of Lua
  12. */
  13. #include <limits.h>
  14. #include "lua.h"
  15. #include "llimits.h"
  16. #define ALPHABIT 0
  17. #define DIGITBIT 1
  18. #define PRINTBIT 2
  19. #define SPACEBIT 3
  20. #define XDIGITBIT 4
  21. #define MASK(B) (1 << (B))
  22. /*
  23. ** add 1 to char to allow index -1 (EOZ)
  24. */
  25. #define testprop(c,p) (luai_ctype_[(c)+1] & (p))
  26. /*
  27. ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
  28. */
  29. #define lislalpha(c) testprop(c, MASK(ALPHABIT))
  30. #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
  31. #define lisdigit(c) testprop(c, MASK(DIGITBIT))
  32. #define lisspace(c) testprop(c, MASK(SPACEBIT))
  33. #define lisprint(c) testprop(c, MASK(PRINTBIT))
  34. #define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
  35. /*
  36. ** this 'ltoupper' only works for alphabetic characters
  37. */
  38. #define ltoupper(c) ((c) & ~32)
  39. /* one more entry for 0 and one more for -1 (EOZ) */
  40. LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
  41. #endif