Module:Ko-utils
Appearance
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
This module contains various functions that are potentially useful for the processing of Korean text (Hangul or Hanja), especialy the various modules and templates that use Module:Ko-translit.
Usage
{{#invoke:Ko-utils|function_name}}
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