Cam's Test Wiki
Advertisement

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

--
-- String functions
--
-- Replacements for [[mw:Extension:StringFunctions]]
-- which is technically part of ParserFunctions, but only documented at the above link
--

-- functions for use through #invoke or in templates
-- largely just wrappers for q, although some extremely simple functions are exclusive to p
local p = {}

-- all these functions can be accessed through p's wrappers
-- except when they return something that isn't a string
--
-- when this module is used in other modules
-- you can call p.module() which will allow direct access to q and
-- skip all the overhead of messing with the frame
local q = {}

local getArgs = require( 'Module:Arguments' ).getArgs

--
-- Returns the length of a string
--
function p.length( str )
    return mw.ustring.len( str )
end

--
-- Returns the position of a given search term in a string
--
function q.pos( str, search )

end

function p.pos( frame )
    return q.pos( str, search )
end

--
-- Returns the last position of a given search term in a string
--
function q.rpos( str, search )

end

function p.rpos( frame )
    return q.rpos( str, search )
end

--
-- Returns a substring from a given string
--
function q.sub( str, start, len )

end

function p.sub( frame )
    return q.sub( str, start, len )
end

--
-- Returns a given string extended to a given length
--
function q.pad( str, len, padstr, dir )

end

function p.pad( frame )
    return q.pad( str, len, padstr, dir )
end

--
-- Returns a given string with all occurrences of a search term replaced with a replacement term
--
function q.replace( str, search, repl )

end

function p.replace( frame )
    return q.replace( str, search, repl )
end

--
-- Splits the given string and returns a table of the results
--
function q.split( str, delim )
    -- because this returns a table rather than a string
    -- it's not designed for use through #invoke, but for use in other modules
    -- so we don't have to mess around with the frame object for our variables
end

--
-- Splits the given string and returns one of the pieces
--
function q.explode( str, delim, pos )
    return q.split( str, delim )[pos]
end

function p.explode( frame )
    return q.explode( str, delim, pos )
end

--
-- Repeats a given string a given number of times
--
function q.rep( str, num )

end

function p.rep( frame )
    return q.rep( str, num )
end

--
-- Allows access to functions for use in 
--
function p.module()
    return q
end

return p
Advertisement