Module:sam-common

local export = {} local lang = require("Module:languages").getByCode("sam")

-- A nil-safe, Semitic-specific diacritic remover. function export.remove_nikud(formwv) return formwv and (lang:makeEntryName(formwv)) end

local vowels = "ࠖ ࠗ ࠘ ࠙ࠚ   ࠛ    ࠜ    ࠝ    ࠞ    ࠟ     ࠠ    ࠡ    ࠢ    ࠣ    ࠤ    ࠥ    ࠦ    ࠧ    ࠨ    ࠩ    ࠪ    ࠫ    ࠬ࠭" local dagesh = "࠙" local nikud_regex = "[" .. dagesh .. vowels .. "]"

local function fix_nikud_subber(x) local s = "" local d = "" local v = "" local subber = function(y) if mw.ustring.match(y, dagesh_regex) then d = d .. y       else v = v .. y       end end mw.ustring.gsub(x, ".", subber) return s .. d .. v end

function export.fix_nikud(x) return mw.ustring.gsub(x, nikud_regex .. "+", fix_nikud_subber) end

function export.end_with_makaf(string) if string == "" or string == nil then return string end if mw.ustring.sub(string, -1) ~= "־" then string = string .. "־"	end return string end

-- This should only be used by modules that auto-generate words, otherwise use gen_link function export.process_wv_triad(form, formwv, formdwv) if form then return form, formwv, formdwv elseif formwv then return export.remove_nikud(formwv), formwv, formdwv else return export.remove_nikud(formdwv), formdwv, nil end end

function export.gen_link(form, formwv, formdwv) form, formwv, formdwv = export.process_wv_triad(form, formwv, formdwv) if not form then error("Can't make a link out of nothing.") end if formdwv then return "" .. (formwv or form) .. " \\ " .. formdwv .. "" else return "" .. (formwv or form) .. "" end end

-- Like gen_link for construct forms appends a makaf if one doesn't already exist function export.gen_link_ending_with_makaf(form, formwv, formdwv) form, formwv, formdwv = export.process_wv_triad(form, formwv, formdwv) if not form then error("Can't make a link out of nothing.") end if formdwv then return "" .. (export.end_with_makaf(formwv) or form) .. " \\ " .. export.end_with_makaf(formdwv) .. "" else return "" .. export.end_with_makaf(formwv or form) .. "" end end

return export