10,731
edits
TheNightAvl (talk | contribs) No edit summary Tag: Reverted |
TheNightAvl (talk | contribs) No edit summary Tag: Reverted |
||
Line 23: | Line 23: | ||
-- and can handle multiple replacements at once. | -- and can handle multiple replacements at once. | ||
local function replace(str, gsubs) | local function replace(str, gsubs) | ||
for from, to in pairs(gsubs) do | for from, to in pairs(gsubs) do | ||
str = tostring(mw.ustring.gsub(str, from, to)) | |||
end | end | ||
return | return str | ||
end | end | ||
Line 87: | Line 86: | ||
end | end | ||
local function | local function hydrate_pattern_p(out_patterns, p_lua, p_categories) | ||
for _, p_pos in ipairs(d_pos) do | |||
local p_out_cats = {} | |||
for _, p_cat in ipairs(p_categories) do | |||
table.insert(p_out_cats, replace(p_cat, {["^%%p"] = capitalize(p_pos), ["%%p"] = p_pos})) | |||
end | |||
table.insert(out_patterns, to_pattern(replace(p_lua, {["^%%p"] = capitalize(p_pos), ["%%p"] = p_pos}), p_out_cats)) | |||
end | end | ||
end | end | ||
Line 107: | Line 104: | ||
hydrate_pattern_l(out_patterns, p_lua, p_categories, mw.ustring.find(p_template, "%%u") ~= nil) | hydrate_pattern_l(out_patterns, p_lua, p_categories, mw.ustring.find(p_template, "%%u") ~= nil) | ||
elseif mw.ustring.find(p_template, "%%c") ~= nil then | elseif mw.ustring.find(p_template, "%%c") ~= nil then | ||
hydrate_pattern_c(out_patterns, p_lua, p_categories) | hydrate_pattern_c(out_patterns, p_lua, p_categories) | ||
elseif mw.ustring.find(p_template, "%%p") ~= nil then | |||
hydrate_pattern_p(out_patterns, p_lua, p_categories) | |||
else | else | ||
table.insert(out_patterns, to_pattern(p_lua, p_categories)) | table.insert(out_patterns, to_pattern(p_lua, p_categories)) | ||
end | end | ||
end | end | ||
return out_patterns | return out_patterns | ||
end | end |