aboutsummaryrefslogtreecommitdiff
path: root/src/ljstype.js
blob: eb24ac51025109f060a405f5ba0431cea2d0b178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"use strict";

const { luastring_of } = require('./defs.js');

const luai_ctype_ = luastring_of(
    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 (luai_ctype_[c+1] & (1<<DIGITBIT)) !== 0;
};

const lisxdigit = function(c) {
    return (luai_ctype_[c+1] & (1<<XDIGITBIT)) !== 0;
};

const lisprint = function(c) {
    return (luai_ctype_[c+1] & (1<<PRINTBIT)) !== 0;
};

const lisspace = function(c) {
    return (luai_ctype_[c+1] & (1<<SPACEBIT)) !== 0;
};

const lislalpha = function(c) {
    return (luai_ctype_[c+1] & (1<<ALPHABIT)) !== 0;
};

const lislalnum = function(c) {
    return (luai_ctype_[c+1] & ((1<<ALPHABIT)|(1<<DIGITBIT))) !== 0;
};

module.exports.lisdigit   = lisdigit;
module.exports.lislalnum  = lislalnum;
module.exports.lislalpha  = lislalpha;
module.exports.lisprint   = lisprint;
module.exports.lisspace   = lisspace;
module.exports.lisxdigit  = lisxdigit;