-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstring_ext.lua
More file actions
39 lines (34 loc) · 1012 Bytes
/
string_ext.lua
File metadata and controls
39 lines (34 loc) · 1012 Bytes
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
function string:case_insensitive_pattern()
local p = self:gsub("(%%?)(.)", function(percent, letter)
if percent ~= "" or not letter:match("%a") then
return percent .. letter;
else
return string.format("[%s%s]", letter:lower(), letter:upper());
end
end);
return p;
end
function string:findi(pattern, init, plain)
if(init ~= nil and plain ~= nil) then
return self:find(pattern:case_insensitive_pattern(), init, plain);
else
return self:find(pattern:case_insensitive_pattern());
end
end
function string:gmatchi(pattern)
return self:gmatch(pattern:case_insensitive_pattern());
end
function string:gsubi(pattern, replace, n)
if(n ~= nil) then
return self:gsub(pattern:case_insensitive_pattern(), replace, n);
else
return self:gsub(pattern:case_insensitive_pattern(), replace);
end
end
function string:matchi(pattern, init)
if(init ~= nil) then
return self:match(pattern:case_insensitive_pattern(), init);
else
return self:match(pattern:case_insensitive_pattern());
end
end