Module:Ko-utils

local p = {}
local find = mw.ustring.find
local hanja_ranges = "[〇㐀-䶿一-鿿﨎﨏﨑﨓﨔﨟﨡﨣﨤﨧-﨩𠀀-𪛟𪜀-𮹟𰀀-𲎯]"

-- Iteratively applies gsub text replacements to a given piece of text 
-- table should contain pairs of search patterns and replacements
function p.gsub_iterate(text, table)
	for _, entry in ipairs(table) do
		text = mw.ustring.gsub(text, entry[1], entry[2])
	end
	return text
end

-- Decomposes Hangul into jamo (e.g. 한 (U+D55C) → ᄒ (U+1112), ᅡ (U+1161), ᆫ (U+11AB))
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 Hangul contains any special chars used by Module:Ko-translit
function p.hangul_contains_syntax(text)
	-- check if string empty
	if text == nil or text == "" then
		return false
	end
	-- check if first char of string is a special char
	if mw.ustring.match(mw.ustring.sub(text, 1, 1), "[%$%%%*@%^_`]") then
		return true
	end
	-- check if the rest of the chars are special
	return find(text, "[^\\][%$%%%*@%^_`]")
end

-- Returns boolean on whether input contains any Hanja text at all
function p.contains_hanja(text)
	return text ~= nil and text ~= "" and find(text, hanja_ranges)
end

-- Returns boolean on whether input only contains Hanja text
function p.all_hanja(text)
    for i = 1, #text do
        local c = text:sub(i, i)
        if not find(c, hanja_ranges) then
            return false
        end
    end
    return true
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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.