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
-- 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 contains any Hanja text at all
function p.contains_hanja(frame)
local hanja_ranges = "[〇㐀-䶿一-鿿﨎﨏﨑﨓﨔﨟﨡﨣﨤﨧-﨩𠀀-𪛟𪜀-𰀀-𲎯]"
local get_args = require('Module:Arguments').getArgs
local args = get_args(frame)
local text = args[1]
if text == nil or text == "" or find(text, hanja_ranges) == nil then
return false
else
return true
end
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