diff options
author | daurnimator <quae@daurnimator.com> | 2018-01-02 00:51:52 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-01-02 00:59:14 +1100 |
commit | dc9eceb56d1d0d37c31887bffc48816bf53ddf3c (patch) | |
tree | 34b7426d048e08d70fb4f3305a5f46f4baa36250 | |
parent | 169b92c6b3d7a4ed9722da4fe0d3279e94f4ea5d (diff) | |
download | fengari-dc9eceb56d1d0d37c31887bffc48816bf53ddf3c.tar.gz fengari-dc9eceb56d1d0d37c31887bffc48816bf53ddf3c.tar.bz2 fengari-dc9eceb56d1d0d37c31887bffc48816bf53ddf3c.zip |
src/ljstype.js: Add built in tables rather than using regex rules
-rw-r--r-- | src/ljstype.js | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/src/ljstype.js b/src/ljstype.js index 2528f74..4d46fa9 100644 --- a/src/ljstype.js +++ b/src/ljstype.js @@ -1,27 +1,69 @@ "use strict"; +const luai_ctype_ = [ + 0x00, /* EOZ */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ + 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ + 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, + 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ + 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +]; + +const ALPHABIT = 0; +const DIGITBIT = 1; +const PRINTBIT = 2; +const SPACEBIT = 3; +const XDIGITBIT = 4; + const lisdigit = function(c) { - return /^\d$/.test(String.fromCharCode(c)); + return (luai_ctype_[c+1] & (1<<DIGITBIT)) !== 0; }; const lisxdigit = function(c) { - return /^[0-9a-fA-F]$/.test(String.fromCharCode(c)); + return (luai_ctype_[c+1] & (1<<XDIGITBIT)) !== 0; }; const lisprint = function(c) { - return /^[\x20-\x7E]$/.test(String.fromCharCode(c)); + return (luai_ctype_[c+1] & (1<<PRINTBIT)) !== 0; }; const lisspace = function(c) { - return /^\s$/.test(String.fromCharCode(c)); + return (luai_ctype_[c+1] & (1<<SPACEBIT)) !== 0; }; const lislalpha = function(c) { - return /^[_a-zA-Z]$/.test(String.fromCharCode(c)); + return (luai_ctype_[c+1] & (1<<ALPHABIT)) !== 0; }; const lislalnum = function(c) { - return /^[_a-zA-Z0-9]$/.test(String.fromCharCode(c)); + return (luai_ctype_[c+1] & ((1<<ALPHABIT)|(1<<DIGITBIT))) !== 0; }; module.exports.lisdigit = lisdigit; |