Module:Color: Difference between revisions
ReisuDesign (talk | contribs) No edit summary |
this SHOULD fix Uncommon getting picked up as Common. |
||
| Line 105: | Line 105: | ||
-- Helper method to search given text for the keys of given table t. | -- Helper method to search given text for the keys of given table t. | ||
-- If a key is found, returns its value; returns nil otherwise. | -- If a key is found, returns its value; returns nil otherwise. | ||
-- Checks longer keys first to avoid matching partial keywords (Uncommon getting detected as Common.) | |||
local function searchTextForKeys(text, t) | local function searchTextForKeys(text, t) | ||
local keys = {} | |||
for key in pairs(t) do | |||
keys[#keys + 1] = key | |||
end | |||
table.sort(keys, function(a, b) | |||
return #a > #b | |||
end) | |||
for _, key in ipairs(keys) do | |||
if mw.ustring.find(text, key, 1, true) ~= nil then | |||
return t[key] | |||
end | |||
end | end | ||
end | end | ||