Difference between revisions of "Module:SandboxUString"

From PKC
Jump to navigation Jump to search
Line 19: Line 19:


function p.luaSourceCodeText(a)
function p.luaSourceCodeText(a)
pageContent = mw.text.encode(mw.getCurrentFrame().args[1], "['<>&\"\' ]")
pageContent = mw.text.encode(mw.getCurrentFrame().args[1], "['<>&\' ]")
local div = mw.html.create( 'syntaxhighlight' )
local div = mw.html.create( 'syntaxhighlight' )
div
div

Revision as of 15:45, 10 January 2022

Documentation for this module may be created at Module:SandboxUString/doc

local p = {}

function p.countChar(a)
	textLength = mw.ustring.len(mw.getCurrentFrame().args[1])
	local div = mw.html.create( 'h1' )
	div
     :wikitext( "The number of characters is:" .. tostring(textLength) )
	return a:preprocess(tostring( div ))
end

function p.showCode(a)
	str = "The Quick Brown Fox Jumped over the lazy dog."
	pageContent = string.byte(str, 5, 9)
	-- resultingText = string.char(113, 117, 105, 99, 107)
	arr = {113, 113, 117, 105, 99, 107}
    resultingText = string.char(arr)
	return resultingText
end

function p.luaSourceCodeText(a)
	pageContent = mw.text.encode(mw.getCurrentFrame().args[1], "['<>&\' ]")
	local div = mw.html.create( 'syntaxhighlight' )
	div
     :attr( 'lang', 'lua' )
     :wikitext( "-- Content:" .. tostring(string.char(pageContent)) )
	return a:preprocess(tostring( div ))
end

function p.byte()
    return ';byte\n:mw.ustring.byte(\'\\\') is ' .. mw.ustring.byte("\\") .. '\n'
end

function p.char()
    return ';char\n:mw.ustring.char(92) is ' .. mw.ustring.char(92) .. '\n'
end
 
function p.codepoint()
    return ';byte\n:mw.ustring.codepoint(\'\') is ' .. mw.ustring.codepoint("张") .. '\n'
end

function p.ustringchar()
    return ';byte\n:mw.ustring.char(24352) is ' .. mw.ustring.char(24352) .. '\n'
end

function p.gsub()
    return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\n'
end
return p