diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-03-26 15:53:52 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-03-26 15:53:52 -0300 |
| commit | b1e1c15ced1f02becf578efb12dbeea6a9f01eee (patch) | |
| tree | 0cbdb7f2b92ed4391d60613d578ca49de3137afd | |
| parent | 3dbf30540892b4b9c86e0cb663069cd478a0c900 (diff) | |
| download | lua-b1e1c15ced1f02becf578efb12dbeea6a9f01eee.tar.gz lua-b1e1c15ced1f02becf578efb12dbeea6a9f01eee.tar.bz2 lua-b1e1c15ced1f02becf578efb12dbeea6a9f01eee.zip | |
small bug: EOZ is a valid character to be tested
| -rw-r--r-- | lctype.c | 5 | ||||
| -rw-r--r-- | lctype.h | 28 |
2 files changed, 21 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lctype.c,v 1.3 2009/03/10 17:42:33 roberto Exp roberto $ | 2 | ** $Id: lctype.c,v 1.4 2009/03/11 13:27:32 roberto Exp roberto $ |
| 3 | ** 'ctype' functions for Lua | 3 | ** 'ctype' functions for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -8,7 +8,8 @@ | |||
| 8 | 8 | ||
| 9 | #include "lctype.h" | 9 | #include "lctype.h" |
| 10 | 10 | ||
| 11 | const char luai_ctype_[UCHAR_MAX + 1] = { | 11 | const char luai_ctype_[UCHAR_MAX + 2] = { |
| 12 | 0x00, /* EOZ */ | ||
| 12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 13 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, | 14 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, |
| 14 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 15 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lctype.h,v 1.3 2009/03/10 17:42:33 roberto Exp roberto $ | 2 | ** $Id: lctype.h,v 1.4 2009/03/11 13:27:32 roberto Exp roberto $ |
| 3 | ** 'ctype' functions for Lua | 3 | ** 'ctype' functions for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -23,16 +23,24 @@ | |||
| 23 | #define MASK(B) (1 << (B)) | 23 | #define MASK(B) (1 << (B)) |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | /* 'lalpha' (Lua alphabetic) includes '_' */ | 26 | /* |
| 27 | #define lislalpha(x) (luai_ctype_[x] & MASK(ALPHABIT)) | 27 | ** add 1 to char to allow index -1 (EOZ) |
| 28 | /* ditto */ | 28 | */ |
| 29 | #define lislalnum(x) (luai_ctype_[x] & (MASK(ALPHABIT) | MASK(DIGITBIT))) | 29 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) |
| 30 | #define lisdigit(x) (luai_ctype_[x] & MASK(DIGITBIT)) | 30 | |
| 31 | #define lisspace(x) (luai_ctype_[x] & MASK(SPACEBIT)) | 31 | /* |
| 32 | #define lisprint(x) (luai_ctype_[x] & MASK(PRINTBIT)) | 32 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' |
| 33 | #define lisxdigit(x) (luai_ctype_[x] & MASK(XDIGITBIT)) | 33 | */ |
| 34 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) | ||
| 35 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) | ||
| 36 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) | ||
| 37 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) | ||
| 38 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) | ||
| 39 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) | ||
| 40 | |||
| 34 | 41 | ||
| 35 | LUAI_DATA const char luai_ctype_[UCHAR_MAX + 1]; | 42 | /* one more entry for 0 and one more for -1 (EOZ) */ |
| 43 | LUAI_DATA const char luai_ctype_[UCHAR_MAX + 2]; | ||
| 36 | 44 | ||
| 37 | #endif | 45 | #endif |
| 38 | 46 | ||
