Jump to content

Module:Ko-utils

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 172.56.232.128 (talk) at 06:33, 20 April 2025 (simpler and more efficient). 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 = "[〇㐀-䶿一-鿿﨎﨏﨑﨓﨔﨟﨡﨣﨤﨧-﨩𠀀-𪛟𪜀-𮹟𰀀-𲎯]"

-- 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[1], pair[2]
		local code = string.byte(text, 1)
		if code >= a and code <= 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