Jump to content

Module:DecodeEncode

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DePiep (talk | contribs) at 15:02, 22 October 2020. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function _getBoolean( boolean_str )
	-- from: module:String; adapted
	-- requires an explicit true
	local boolean_value

	if type( boolean_str ) == 'string' then
		boolean_str = boolean_str:lower()
		if boolean_str == 'true' or boolean_str == 'yes' or boolean_str == '1' then
			boolean_value = true
		else
			boolean_value = false
		end
	elseif type( boolean_str ) == 'boolean' then
		boolean_value = boolean_str
	else
		boolean_value = false
	end
	return boolean_value
end

function p.decode( frame )
	local s
	local XMLonly 

	s = frame.args['s'] or ''
	XMLonly = _getBoolean(frame.args['XMLonly'] or false)

	p._decode( s, XMLonly )
end

function p._decode( s, XMLonly )
	local ret = nil;
	
local stext = 'unk'
if XMLonly==nil then
	stext='nil'
elseif XMLonly==false then
		stext='F'
else
		stext='T'
end

	ret = mw.text.decode( s, not XMLonly )  .. ' (dbg: s: ' .. s .. ' XMLonly: ' .. stext ..')'

	return ret
end

function p.encode( frame )
	local ret = textEncode-todo

	return ret
end

return p