Module:Grek-common

From Linguifex
Revision as of 14:26, 7 May 2026 by Sware (talk | contribs) (Created page with "local export = {} local toNFC = mw.ustring.toNFC local toNFD = mw.ustring.toNFD local u = require("Module:string/char") local ugsub = mw.ustring.gsub local PRIME = u(0x02B9) local CARON = u(0x030C) local DIAERBELOW = u(0x0324) local BREVEBELOW = u(0x032E) local KERAIA = u(0x0374) local CORONIS = u(0x1FBD) local PSILI = u(0x1FBF) local RSQUO = u(0x2019) local displaytext_substitutes = { ["'"] = RSQUO, [PRIME] = RSQUO, [KERAIA] = RSQUO, [CORONIS] = RSQUO, [PSILI] =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Grek-common/doc

local export = {}

local toNFC = mw.ustring.toNFC
local toNFD = mw.ustring.toNFD
local u = require("Module:string/char")
local ugsub = mw.ustring.gsub

local PRIME = u(0x02B9)
local CARON = u(0x030C)
local DIAERBELOW = u(0x0324)
local BREVEBELOW = u(0x032E)
local KERAIA = u(0x0374)
local CORONIS = u(0x1FBD)
local PSILI = u(0x1FBF)
local RSQUO = u(0x2019)

local displaytext_substitutes = {
	["'"] = RSQUO,
	[PRIME] = RSQUO,
	[KERAIA] = RSQUO,
	[CORONIS] = RSQUO,
	[PSILI] = RSQUO,
	["Þ"] = "Ϸ",
	["þ"] = "ϸ",
}

function export.makeDisplayText(text, lang, sc)
	return toNFC(ugsub(toNFD(text), "['" .. PRIME .. KERAIA .. CORONIS .. PSILI .. "Þþ]", displaytext_substitutes))
end

local stripdiacritics_substitutes = {}
for k, v in pairs(displaytext_substitutes) do
	stripdiacritics_substitutes[k == "'" and RSQUO or k] = v == RSQUO and "'" or v
end

function export.stripDiacritics(text, lang, sc)
	text = ugsub(toNFD(text), "[" .. PRIME .. KERAIA .. CORONIS .. PSILI .. RSQUO .. "Þþ]", stripdiacritics_substitutes)
	if sc == "Grek" then
		text = ugsub(toNFD(text), "[" .. CARON .. DIAERBELOW .. BREVEBELOW .. "]+", "")
	end
	return toNFC(text)
end

return export