モジュール:eu-common
表示
このモジュールについての説明文ページを モジュール:eu-common/doc に作成できます
local export = {}
local m_string_utilities = require("モジュール:string utilities")
local m_links = require("モジュール:links")
local lang = require("モジュール:languages").getByCode("eu")
local rsub = m_string_utilities.gsub
local rfind = m_string_utilities.find
--Try to match two <hi> forms
function export.make_hik_link(masc, fem)
if rfind(masc, "k$") and rfind(fem, "n$") then
return "/" .. m_links.full_link({lang = lang, term = fem, alt = "n"})
elseif rfind(masc, "an$") and rfind(fem, "nan$") then
return "/" .. m_links.full_link({lang = lang, term = fem, alt = "nan"})
elseif rfind(masc, "ake$") and rfind(fem, "nake$") then
return "/" .. m_links.full_link({lang = lang, term = fem, alt = "nake"})
elseif rfind(masc, "akeen$") and rfind(fem, "nake$") then
return "/" .. m_links.full_link({lang = lang, term = fem, alt = "nakeen"})
elseif rfind(masc, "ala$") and rfind(fem, "nala$") then
return "/" .. m_links.full_link({lang = lang, term = fem, alt = "nala"})
end
return nil
end
--Apply multiple substitutions to a string
function export.rsub_multiple(text, original, changed)
if #original ~= #changed then
error("引数2と3の長さは同じである必要があります")
end
for i = 1, #original do
text = rsub(text, original[i], changed[i])
end
return text
end
--Return true if any of the strings in search is found
function export.rfind_multiple(text, search)
for _, i in ipairs(search) do
if rfind(text, i) then
return true
end
end
return false
end
--FIXME: Is this function (or a similar one) defined anywhere else?
function export.tables_equal(t1, t2)
if #t1 ~= #t2 then return false end
for i = 1, #t1 do
if t1[i] ~= t2[i] then return false end
end
return true
end
--Generate a numbered list of notes. The notes can be formatted as {"Note1", "Note2", ...} or {{"Note1Text", ...}, {"Note2Text", ...}, ...}
function export.generate_notes_text(note_list)
local notes_text = ""
for i, note in ipairs(note_list) do
notes_text = notes_text .. i .. ". " .. (type(note) == "string" and note or note[1])
if i < #note_list then notes_text = notes_text .. "<br/>" end
end
return notes_text
end
return export