Jump to content

Module:Ko-utils

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Seefooddiet (talk | contribs) at 04:52, 20 April 2025 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}
local find = mw.ustring.find
local hani_ranges = {
	{ 0x02E80, 0x02E99 },
	{ 0x02E9B, 0x02EF3 },
	{ 0x02F00, 0x02FD5 },
	{ 0x03021, 0x03029 },
	{ 0x03038, 0x0303B },
	{ 0x03400, 0x04DBF },
	{ 0x04E00, 0x09FFF },
	{ 0x0F900, 0x0FA6D },
	{ 0x0FA70, 0x0FAD9 },
	{ 0x16FE2, 0x16FE3 },
	{ 0x16FF0, 0x16FF1 },
	{ 0x20000, 0x2A6DF },
	{ 0x2A700, 0x2B739 },
	{ 0x2B740, 0x2B81D },
	{ 0x2B820, 0x2CEA1 },
	{ 0x2CEB0, 0x2EBE0 },
	{ 0x2EBF0, 0x2EE5D },
	{ 0x2F800, 0x2FA1D },
	{ 0x30000, 0x3134A },
	{ 0x31350, 0x323AF },
}

-- Decomposes Hangul into jamo
function p.decompose_hangul(text)
	return mw.ustring.gsub(text, "[가-힣]", mw.ustring.toNFD)
end

-- Returns boolean on whether input contains any Hangul text at all
function p.contains_hangul(text)
	local hangul_ranges = "[ᄀ-ᇿ〮〯ㄱ-ㆎ㈀-㈞㉠-㉾ꥠ-꥿가-힣ힰ-퟿]"
	return text ~= nil and text ~= "" and find(text, hangul_ranges)
end

-- Returns boolean on whether input contains any Hanja text at all
function p.contains_hanja(frame)
	local get_args = require('Module:Arguments').getArgs
	local args = get_args(frame)
	local text = args[1]
	for _, pair in ipairs(hani_ranges) do
		local a, b = pair
		return a, b
		-- if text >= a and text <= b then
		-- 	return true
		-- end
	end
	return false
end


-- Returns boolean on whether input directly contains a Wikipedia reference
function p.contains_reference(text)
	return find(text, "'\"`UNIQ--") or find(text, "-QINU`\"'")
end

return p