Module:String: Difference between revisions
Content added Content deleted
Enwikipedia>Mr. Stradivarius m (use tabs instead of spaces, and remove trailing whitespace) |
Enwikipedia>RexxS (export str._match function for use in other modules - syncing from sandbox) |
||
Line 148: | Line 148: | ||
]] |
]] |
||
-- This sub-routine is exported for use in other modules |
|||
⚫ | |||
function str._match( s, pattern, start, match_index, plain, nomatch ) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if s == '' then |
if s == '' then |
||
return str._error( 'Target string is empty' ); |
return str._error( 'Target string is empty' ); |
||
Line 163: | Line 156: | ||
return str._error( 'Pattern string is empty' ); |
return str._error( 'Pattern string is empty' ); |
||
end |
end |
||
start = tonumber(start) or 1 |
|||
if math.abs(start) < 1 or math.abs(start) > mw.ustring.len( s ) then |
if math.abs(start) < 1 or math.abs(start) > mw.ustring.len( s ) then |
||
return str._error( 'Requested start is out of range' ); |
return str._error( 'Requested start is out of range' ); |
||
Line 214: | Line 208: | ||
return result; |
return result; |
||
end |
end |
||
end |
|||
-- This is the entry point for #invoke:String|match |
|||
⚫ | |||
local new_args = str._getParameters( frame.args, {'s', 'pattern', 'start', 'match', 'plain', 'nomatch'} ); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return str._match( s, pattern, start, match_index, plain, nomatch ) |
|||
end |
end |
||