blob: 1481e84db6f200e84a4d5379c0f7c68b3d19d532 (
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
|
local pattern = {}
pattern._regexes = {}
pattern.regex = function(p)
if not pattern._regexes[p] then
pattern._regexes[p] = vim.regex(p)
end
return pattern._regexes[p]
end
pattern.offset = function(p, text)
local s, e = pattern.regex(p):match_str(text)
if s then
return s + 1, e + 1
end
return nil, nil
end
pattern.matchstr = function(p, text)
local s, e = pattern.offset(p, text)
if s then
return string.sub(text, s, e)
end
return nil
end
return pattern
|