blob: f7b789023077579ad7fa7a2cca5a606dbf637675 (
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
|
return function(utf8)
os.setlocale(utf8.config.locale, "ctype")
local ffi = require("ffi")
ffi.cdef[[
int iswalnum(int c);
int iswalpha(int c);
int iswascii(int c);
int iswblank(int c);
int iswcntrl(int c);
int iswdigit(int c);
int iswgraph(int c);
int iswlower(int c);
int iswprint(int c);
int iswpunct(int c);
int iswspace(int c);
int iswupper(int c);
int iswxdigit(int c);
]]
local base = utf8:require "charclass.runtime.base"
local native = setmetatable({}, {__index = base})
local mt = {__index = native}
function native.new()
return setmetatable({}, mt)
end
function native:is(class, char_code)
if class == 'alpha' then return ffi.C.iswalpha(char_code) ~= 0
elseif class == 'cntrl' then return ffi.C.iswcntrl(char_code) ~= 0
elseif class == 'digit' then return ffi.C.iswdigit(char_code) ~= 0
elseif class == 'graph' then return ffi.C.iswgraph(char_code) ~= 0
elseif class == 'lower' then return ffi.C.iswlower(char_code) ~= 0
elseif class == 'punct' then return ffi.C.iswpunct(char_code) ~= 0
elseif class == 'space' then return ffi.C.iswspace(char_code) ~= 0
elseif class == 'upper' then return ffi.C.iswupper(char_code) ~= 0
elseif class == 'alnum' then return ffi.C.iswalnum(char_code) ~= 0
elseif class == 'xdigit' then return ffi.C.iswxdigit(char_code) ~= 0
end
end
return native
end
|