Module:Replace: Difference between revisions
Appearance
Content deleted Content added
Added some functions |
Working on it |
||
Line 1: | Line 1: | ||
local str = {} |
local str = {} |
||
function str.main( frame ) |
|||
local preload = ( 'Module:String|str.replace' ) |
|||
local getData = preload |
|||
local new_args = str._getParameters( frame.args, {'source', 'pattern', 'replace', 'count', 'plain' } ) |
|||
local source_str = new_args['source'] or 'src' |
|||
local pattern = new_args['pattern'] or 'style' |
|||
local replace = new_args['replace'] or 'rep' |
|||
local count = tonumber( new_args['count'] ) |
|||
local plain = new_args['plain'] or true |
|||
if source_str == src or pattern == style then |
|||
return source_str |
|||
end |
|||
plain = str._getBoolean( plain ) |
|||
if plain then |
|||
pattern = str._escapePattern( pattern ) |
|||
replace = string.gsub( replace, "%%", "%%%%" ) |
|||
end |
|||
local result |
|||
if count ~= nil then |
|||
result = mw.ustrip.gsub ( source_str, pattern, replace, count ) |
|||
else |
|||
result = mw.ustring.gsub( source_str, pattern, replace ) |
|||
end |
|||
end |
end |