Module:he-common

Hello, you have come here looking for the meaning of the word Module:he-common. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:he-common, but we will also tell you about its etymology, its characteristics and you will know how to say Module:he-common in singular and plural. Everything you need to know about the word Module:he-common you have here. The definition of the word Module:he-common will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:he-common, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module holds some common used functions for Hebrew, that are needed by other modules.


local export = {}

local concat = table.concat
local insert = table.insert
local u = mw.ustring.char
local ugsub = mw.ustring.gsub
local usub = mw.ustring.sub

local lang = require("Module:languages").getByCode("he")

local nikud_regex = ""

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

local function fix_nikud_subber(x)
	local ret = {}
	-- Shin dots (U+05C1 & U+05C2).
	for s in x:gmatch("\215") do
		insert(ret, s)
	end
	-- Dagesh (U+05BC & U+05BF).
	for d in x:gmatch("\214") do
		insert(ret, d)
	end
	-- Vowels (U+05B0-U+05BB & U+05C7).
	for v in x:gmatch("") do -- any false-positives won't be picked up by the original gsub
		insert(ret, v)
	end
	return concat(ret)
end

function export.fix_nikud(x)
    return ugsub(x, nikud_regex .. nikud_regex .. "+", fix_nikud_subber)
end

function export.end_with_makaf(str)
	if str and #str > 0 and usub(str, -1) ~= "־" then
		str = str .. "־"
	end
	return str
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
	end
	return export.remove_nikud(formdwv), formdwv, nil
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.")
	elseif formdwv then
		return "]"
	end
	return "]"
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.")
	elseif formdwv then
		return "]"
	end
	return "]"
end

return export