Difference between revisions of "Module:SandboxUString"

From PKC
Jump to navigation Jump to search
 
(64 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(3229) is ' .. mw.ustring.char(3229) .. '\n'
 
           
str = "\\\"\'ABCDabc<>\\\"\'D";
return a:preprocess(str:gsub("%p", rTable))
end
end
 
function p.find()
function p.htmlSourceCodeText(a)
    return ';find\n:string.find(\'that\', \'at\') is ' .. string.find('that', 'at') .. '\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.format()
function p.yamlSourceCodeText(a)
    return ';format\n:string.format(\'%.2f\', 0) is ' .. string.format('%.2f', 0) .. '\n'
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
end
 
function p.gmatch()
 
local result = ';gmatch\n:'
function p.luaSourceCodeText(a)
for word in string.gmatch('This is a test', '%w+') do
lTable = {}
result = result .. word .. '-'
pageContent = mw.getCurrentFrame().args[1]
end
local div = mw.html.create( 'syntaxhighlight' )
    return result .. '\n'
div
    :attr( 'lang', 'lua' )
    :wikitext( pageContent:gsub("%p", lTable))
return a:preprocess(tostring( div ))
end
end
 
function p.gsub()
function p.byte()
     return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\n'
     return ';byte\n:mw.ustring.byte(\'\\\') is ' .. mw.ustring.byte("\\") .. '\n'
end
end
 
function p.len()
function p.char()
     return ';len\n:string.len(\'len\') is ' .. string.len('len') .. '\n'
     return ';char\n:mw.ustring.char(92) is ' .. mw.ustring.char(92) .. '\n'
end
end
   
   
function p.lower()
function p.codepoint()
     return ';lower\n:string.lower(\'LOWER\') is ' .. string.lower('LOWER') .. '\n'
     return ';byte\n:mw.ustring.codepoint(\'\') is ' .. mw.ustring.codepoint("张") .. '\n'
end
end
 
function p.match()
function p.ustringchar()
     return ';match\n:string.match(\'This is a test!\', \'.\', -1) is ' .. string.match('This is a test!', '.', -1) .. '\n'
     return ';byte\n:mw.ustring.char(24352) is ' .. mw.ustring.char(24352) .. '\n'
end
end
 
function p.rep()
function p.gsub()
     return ';rep\n:string.rep(\'*\', 5) is ' .. string.rep('*', 5) .. '\n'
     return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\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
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