Module:User:Suzukaze-c/unicode

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Suzukaze-c, for their own experimentation. Items in this module may be added and removed at Suzukaze-c's discretion; do not rely on this module's stability.


local export = {}

function export.show(text, prefix, case, separator)
	if type(text) == "table" then
		local a = text.args
		text = a[1] or nil
		prefix = a[2] or nil
		case = a[3] or nil
		separator = a[4] or nil
	end
	if not text then text = "test string" end
	if not prefix then prefix = "U+" end
	if not case then case = "upper" end
	if not separator then separator = " " end

	local cp = {}

	for char in mw.text.gsplit(text, "") do
		char = mw.ustring.codepoint(char)
		char = string.format('%.4X', char) -- see [[Module:character info]]

		if case == "lower" then
			char = string.lower(char)
		end

		table.insert(cp, prefix .. char)
	end

	return table.concat(cp, separator)
end

return export