Module:StringBools
Jump to navigation
Jump to search
Documentation for this module may be created at Module:StringBools/doc
local strBool = {}
function strBool.startsWith( frame )
local testString = frame.args.string
local startTest = strBool._escapePattern( frame.args.test )
if testString:find('^' .. startTest) ~= nil then
return "true"
end
return "false"
end
function strBool.endsWith( frame )
local testString = frame.args.string
local endTest = frame.args.test
if string.sub( testString, -(#endTest) ) == endTest then
return "true"
end
return "false"
end
--[[
Helper function that escapes all pattern characters so that they will be treated
as plain text.
]]
function strBool._escapePattern( pattern_str )
return ( string.gsub( pattern_str, "[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%0" ) )
end
return strBool