Jump to content

Module:String: Difference between revisions

583 bytes added ,  5 years ago
add an escapePattern function for escaping Lua patterns
m (Changed protection level for "Module:String": request at RfP ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
(add an escapePattern function for escaping Lua patterns)
Line 393: Line 393:
     end
     end
     return string.rep( frame.args[1] or '', repetitions )
     return string.rep( frame.args[1] or '', repetitions )
end
--[[
escapePattern
This function escapes special characters from a Lua string pattern. See [1]
for details on how patterns work.
[1] https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Patterns
Usage:
{{#invoke:String|escapePattern|pattern_string}}
Parameters
    pattern_string: The pattern string to escape.
]]
function str.escapePattern( frame )
    local pattern_str = frame.args[1]
    if not pattern_str then
        return str._error( 'No pattern string specified' );
    end
    local result = str._escapePattern( pattern_str )
    return result
end
end


Cookies help us deliver our services. By using our services, you agree to our use of cookies.