diff options
Diffstat (limited to 'script-beta/core/matchkey.lua')
-rw-r--r-- | script-beta/core/matchkey.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/script-beta/core/matchkey.lua b/script-beta/core/matchkey.lua new file mode 100644 index 00000000..b46250cb --- /dev/null +++ b/script-beta/core/matchkey.lua @@ -0,0 +1,30 @@ +return function (me, other) + if me == other then + return true + end + if me == '' then + return true + end + if #me > #other then + return false + end + local lMe = me:lower() + local lOther = other:lower() + if lMe == lOther:sub(1, #lMe) then + return true + end + local chars = {} + for i = 1, #lOther do + local c = lOther:sub(i, i) + chars[c] = (chars[c] or 0) + 1 + end + for i = 1, #lMe do + local c = lMe:sub(i, i) + if chars[c] and chars[c] > 0 then + chars[c] = chars[c] - 1 + else + return false + end + end + return true +end |