Module:String

Revision as of 01:13, 17 May 2013 by mw>Krinkle

This module was imported from MediaWiki on 11:15, 18 February 2022 (JST). For documentation, please visit the corresponding MediaWiki page, Module:String/doc.


local p = {}

function p.length( frame )
    local arg1 = frame.args[1]
    return string.len( arg1 )
end    

function p.sub( frame )
    local arg1 = frame.args[1]
    local arg2 = tonumber( frame.args[2] )
    local arg3 = tonumber( frame.args[3] )
    if arg2 and arg3 then
        local first = arg2 + 1
        local last  = arg2 + arg3
        return string.sub( arg1, first, last )
    else
        return ""
    end
end  

--[[
This function implements that features of {{str sub old}} and is kept in order
to maintain these older templates.
]]
function p.sublength( frame )
    local i = tonumber( frame.args.i ) or 0
    local len = tonumber( frame.args.len )
    return mw.ustring.sub( frame.args.s, i + 1, len and ( i + len ) )
end

return p