Jump to content

မေႃႇၵျူး:shn-utilities

လုၵ်ႉတီႈ ဝိၵ်ႇသျိၼ်ႇၼရီႇ မႃး

Documentation for this module may be created at မေႃႇၵျူး:shn-utilities/doc

local export = {}

local gsub = mw.ustring.gsub
local find = mw.ustring.find
local match = mw.ustring.match
local en_utilities = require("Module:en-utilities")

local shn_digits = {"႐", "႑", "႒", "႓", "႔", "႕", "႖", "႗", "႘", "႙"}

-- from [[Module:headword/data]]
local shn_pos = {
	-- these are lemmas
	["nouns"] = "ႁိၵ်ႈ",
	["noun forms"] = "ပိူင်ႁိၵ်ႈ",
	["verbs"] = "သၢင်ႈ",
	["verb forms"] = "ပိူင်သၢင်ႈ",
	["adjectives"] = "ၵမ်ႉႁိၵ်ႈ",
	["adjective forms"] = "ပိူင်ၵမ်ႉႁိၵ်ႈ",
	["adverbs"] = "ၵမ်ႉသၢင်ႈ",
	["adverb forms"] = "ပိူင်ၵမ်ႉသၢင်ႈ",
	["interjections"] = "တိုၼ်ႇ",
	["interjection forms"] = "ပိူင်တိုၼ်ႇ",
	["pronouns"] = "ႁိၵ်ႈတၢင်",
	["pronoun forms"] = "ပိူင်ႁိၵ်ႈတၢင်",
	["prepositions"] = "ႁဵင်း",
	["preposition forms"] = "ပိူင်ႁဵင်း",
}

function export.shn_pos(pos)
	return shn_pos[pos] or shn_pos[en_utilities.pluralize(pos)] or pos
end

function export.arabic_digit_to_shn(text)
	if type(text) == "number" then
		text = tostring(text) -- convert to string
	end
	if type(text) == "string" and find(text, "[0-9]") then
		for n = 0, 9 do
			text = gsub(text, tostring(n), shn_digits[n + 1])
		end
	end
	return text
end

function export.shn_digit_to_arabic(text)
	if type(text) == "string" and find(text, "[႐-႙]") then
		for n = 0, 9 do
			text = gsub(text, shn_digits[n + 1], tostring(n))
		end
	end
	return text
end

function export.shn_number_sequence(text)
	if type(text) == "number" then
		text = tostring(text) -- convert to string
	end
	if type(text) == "string" then
		text = export.shn_digit_to_arabic(text)
		for n = 0, 9 do
			text = gsub(text, tostring(n), shn_words[n + 1])
		end
		text = gsub(text, ".", shn_words2)
	end
	return text
end

--([\-+]?)([0-9,]*)((\.[0-9]+)?)

function export.shn_number_integer(text)
	if type(text) == "number" then
		text = tostring(text) -- convert to string
	end
	if type(text) == "string" and match(text, "^[-%+−]?[0-9႐-႙,]+$") then
		text = export.shn_digit_to_arabic(text)
		text = gsub(text, ",", "")
		local len = text:len() -- now only Arabic digits
		--TODO
	end
	return text
end

function export.shn_number_float(text)
	if type(text) == "number" then
		-- floating-point may be not accurate due to binary system
		text = tostring(text) -- convert to string
	end
	if type(text) == "string" then
		--TODO
	end
	return text
end

return export