Difference between revisions of "Module:SandboxUString"

From PKC
Jump to navigation Jump to search
 
(51 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
   
rTable = {
ustring = require('ustring')
            ['<']='&-left', ['>']='&-right',  
            ['\\']='/',['\"']='*',['\'']='^'
function p.byte()
            }
    return ';byte\n:mw.ustring.byte(\'张\') is ' .. mw.ustring.byte("") .. '\n'
           
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
end


function p.char()
function p.showCode(a)
    return ';char\n:mw.ustring.char(229) is ' .. mw.ustring.char(229) .. '\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'
str = "\\\"\'ABCDabc<>\\\"\'D";
return a:preprocess(str:gsub("%p", rTable))
end
end


function p.length()
function p.htmlSourceCodeText(a)
    return ';byte\n:mw.ustring.len(\'张三\') is ' .. mw.ustring.len("张三") .. '\n'
lTable = {}
pageContent = mw.getCurrentFrame().args[1]
local div = mw.html.create( 'syntaxhighlight' )
div
    :attr( 'lang', 'HTML' )
    :wikitext( pageContent:gsub("%p", lTable))
return a:preprocess(tostring( div ))
end
end


function p.countChar(a)
function p.yamlSourceCodeText(a)
textLength = mw.ustring.len(mw.getCurrentFrame().args[1])
lTable = {}
local div = mw.html.create( 'h1' )
pageContent = mw.getCurrentFrame().args[1]
local div = mw.html.create( 'syntaxhighlight' )
div
div
     :attr( 'lang', 'lua' )
     :attr( 'lang', 'YAML' )
     :wikitext( textLength )
     :wikitext( pageContent:gsub("%p", lTable))
return a:preprocess(tostring( div ))
return a:preprocess(tostring( div ))
end
end


function p.luaSourceCodeText(a)
function p.luaSourceCodeText(a)
pageContent = mw.text.encode(mw.getCurrentFrame().args[1])
lTable = {}
pageContent = mw.getCurrentFrame().args[1]
local div = mw.html.create( 'syntaxhighlight' )
local div = mw.html.create( 'syntaxhighlight' )
div
div
     :attr( 'lang', 'lua' )
     :attr( 'lang', 'lua' )
     :wikitext( pageContent )
     :wikitext( pageContent:gsub("%p", lTable))
return a:preprocess(tostring( div ))
return a:preprocess(tostring( div ))
end
end


function p.find()
function p.byte()
     return ';find\n:string.find(\'that\', \'at\') is ' .. string.find('that', 'at') .. '\n'
     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
end
   
   
function p.format()
function p.codepoint()
     return ';format\n:string.format(\'%.2f\', 0) is ' .. string.format('%.2f', 0) .. '\n'
     return ';byte\n:mw.ustring.codepoint(\'\') is ' .. mw.ustring.codepoint("张") .. '\n'
end
end
 
function p.gmatch()
function p.ustringchar()
local result = ';gmatch\n:'
    return ';byte\n:mw.ustring.char(24352) is ' .. mw.ustring.char(24352) .. '\n'
for word in string.gmatch('This is a test', '%w+') do
result = result .. word .. '-'
end
    return result .. '\n'
end
end
 
function p.gsub()
function p.gsub()
     return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\n'
     return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\n'
end
end
function p.len()
    return ';len\n:string.len(\'len\') is ' .. string.len('len') .. '\n'
end
function p.lower()
    return ';lower\n:string.lower(\'LOWER\') is ' .. string.lower('LOWER') .. '\n'
end
function p.match()
    return ';match\n:string.match(\'This is a test!\', \'.\', -1) is ' .. string.match('This is a test!', '.', -1) .. '\n'
end
function p.rep()
    return ';rep\n:string.rep(\'*\', 5) is ' .. string.rep('*', 5) .. '\n'
end
function p.reverse()
    return ';reverse\n:string.reverse(\'reverse\') is ' .. string.reverse('reverse') .. '\n'
end
function p.sub()
    return ';sub\n:string.sub(\'that\', 2, 3) is ' .. string.sub('that', 2, 3) .. '\n'
end
function p.upper()
    return ';upper\n:string.upper(\'upper\') is ' .. string.upper('upper') .. '\n'
end
return p
return p

Latest revision as of 14:33, 11 January 2022

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

local p = {}
	rTable = {
             ['<']='&-left', ['>']='&-right',  
             ['\\']='/',['\"']='*',['\'']='^'
             }
             
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 = "\\\"\'ABCDabc<>\\\"\'D";
	return a:preprocess(str:gsub("%p", rTable))
end

function p.htmlSourceCodeText(a)
	lTable = {}
	pageContent = mw.getCurrentFrame().args[1]
	local div = mw.html.create( 'syntaxhighlight' )
	div
     :attr( 'lang', 'HTML' )
     :wikitext( pageContent:gsub("%p", lTable))
	return a:preprocess(tostring( div ))
end

function p.yamlSourceCodeText(a)
	lTable = {}
	pageContent = mw.getCurrentFrame().args[1]
	local div = mw.html.create( 'syntaxhighlight' )
	div
     :attr( 'lang', 'YAML' )
     :wikitext( pageContent:gsub("%p", lTable))
	return a:preprocess(tostring( div ))
end


function p.luaSourceCodeText(a)
	lTable = {}
	pageContent = mw.getCurrentFrame().args[1]
	local div = mw.html.create( 'syntaxhighlight' )
	div
     :attr( 'lang', 'lua' )
     :wikitext( pageContent:gsub("%p", lTable))
	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