Module:String: Difference between revisions
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 | ||