No need for the case_insensitive function, can just :lower() the string + use plain matching
This commit is contained in:
parent
d7f23096d4
commit
24cdcb9385
|
@ -71,24 +71,9 @@ local function string_levenshtein(str1, str2)
|
||||||
return matrix[len1][len2]
|
return matrix[len1][len2]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function case_insensitive_pattern(pattern)
|
|
||||||
-- find an optional '%' (group 1) followed by any character (group 2)
|
|
||||||
local p = pattern:gsub("(%%?)(.)", function(percent, letter)
|
|
||||||
if percent ~= "" or not letter:match("%a") then
|
|
||||||
-- if the '%' matched, or `letter` is not a letter, return "as is"
|
|
||||||
return percent .. letter
|
|
||||||
else
|
|
||||||
-- else, return a case-insensitive character class of the matched letter
|
|
||||||
return string.format("[%s%s]", letter:lower(), letter:upper())
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
return p
|
|
||||||
end
|
|
||||||
|
|
||||||
local function has_value(tab, val)
|
local function has_value(tab, val)
|
||||||
for index, value in pairs(tab) do
|
for _, value in ipairs(tab) do
|
||||||
if val:find(case_insensitive_pattern(value)) then
|
if val:lower():find(value:lower(), 1, true) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue