<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AUnicode_convert</id>
	<title>Module:Unicode convert - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AUnicode_convert"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Unicode_convert&amp;action=history"/>
	<updated>2026-04-21T16:10:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Unicode_convert&amp;diff=147424&amp;oldid=prev</id>
		<title>imported&gt;GKFX: Add fromUTF8 function</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Unicode_convert&amp;diff=147424&amp;oldid=prev"/>
		<updated>2021-04-11T13:12:30Z</updated>

		<summary type="html">&lt;p&gt;Add fromUTF8 function&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
-- NOTE: all these functions use frame solely for its args member.&lt;br /&gt;
-- Modules using them may therefore call them with a fake frame table&lt;br /&gt;
-- containing only args.&lt;br /&gt;
&lt;br /&gt;
p.getUTF8 = function (frame)&lt;br /&gt;
	local ch = mw.ustring.char(tonumber(frame.args[1] or &amp;#039;0&amp;#039;, 16) or 0)&lt;br /&gt;
	local bytes = {mw.ustring.byte(ch, 1, -1)}&lt;br /&gt;
	local format = ({&lt;br /&gt;
		[&amp;#039;10&amp;#039;] = &amp;#039;%d&amp;#039;,&lt;br /&gt;
		dec = &amp;#039;%d&amp;#039;&lt;br /&gt;
	})[frame.args[&amp;#039;base&amp;#039;]] or &amp;#039;%02X&amp;#039;&lt;br /&gt;
	for i = 1, #bytes do&lt;br /&gt;
		bytes[i] = format:format(bytes[i])&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat(bytes, &amp;#039; &amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.getUTF16 = function (frame)&lt;br /&gt;
	local codepoint = tonumber(frame.args[1] or &amp;#039;0&amp;#039;, 16) or 0&lt;br /&gt;
	local format = ({ -- TODO reduce the number of options.&lt;br /&gt;
		[&amp;#039;10&amp;#039;] = &amp;#039;%d&amp;#039;,&lt;br /&gt;
		dec = &amp;#039;%d&amp;#039;&lt;br /&gt;
	})[frame.args[&amp;#039;base&amp;#039;]] or &amp;#039;%04X&amp;#039;&lt;br /&gt;
	if codepoint &amp;lt;= 0xFFFF then -- NB this also returns lone surrogate characters&lt;br /&gt;
		return format:format(codepoint)&lt;br /&gt;
	elseif codepoint &amp;gt; 0x10FFFF then -- There are no codepoints above this&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	codepoint = codepoint - 0x10000&lt;br /&gt;
	bit32 = require(&amp;#039;bit32&amp;#039;)&lt;br /&gt;
	return (format .. &amp;#039; &amp;#039; .. format):format(&lt;br /&gt;
		bit32.rshift(codepoint, 10) + 0xD800,&lt;br /&gt;
		bit32.band(codepoint, 0x3FF) + 0xDC00)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.fromUTF8 = function(frame)&lt;br /&gt;
	local basein = frame.args[&amp;#039;basein&amp;#039;] == &amp;#039;dec&amp;#039; and 10 or 16&lt;br /&gt;
	local format = frame.args[&amp;#039;base&amp;#039;] == &amp;#039;dec&amp;#039; and &amp;#039;%d &amp;#039; or &amp;#039;%02X &amp;#039;&lt;br /&gt;
	local bytes = {}&lt;br /&gt;
	for byte in mw.text.gsplit(frame.args[1], &amp;#039;%s&amp;#039;) do&lt;br /&gt;
		table.insert(bytes, tonumber(byte, basein))&lt;br /&gt;
	end&lt;br /&gt;
	local chars = {mw.ustring.codepoint(string.char(unpack(bytes)), 1, -1)}&lt;br /&gt;
	return format:rep(#chars):sub(1, -2):format(unpack(chars))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;GKFX</name></author>
	</entry>
</feed>