Module:String: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
export str._match function for use in other modules - syncing from sandbox
m (use tabs instead of spaces, and remove trailing whitespace)
(export str._match function for use in other modules - syncing from sandbox)
Line 148:
 
]]
-- This sub-routine is exported for use in other modules
function str.match( frame )
local new_args =function str._getParameters_match( frame.args, {'s', 'pattern', 'start', 'match'match_index, 'plain', 'nomatch'} );
local s = new_args['s'] or '';
local start = tonumber( new_args['start'] ) or 1;
local plain_flag = str._getBoolean( new_args['plain'] or false );
local pattern = new_args['pattern'] or '';
local match_index = math.floor( tonumber(new_args['match']) or 1 );
local nomatch = new_args['nomatch'];
 
if s == '' then
return str._error( 'Target string is empty' );
Line 163 ⟶ 156:
return str._error( 'Pattern string is empty' );
end
start = tonumber(start) or 1
if math.abs(start) < 1 or math.abs(start) > mw.ustring.len( s ) then
return str._error( 'Requested start is out of range' );
Line 214 ⟶ 208:
return result;
end
end
-- This is the entry point for #invoke:String|match
function str.match( frame )
local new_args = str._getParameters( frame.args, {'s', 'pattern', 'start', 'match', 'plain', 'nomatch'} );
local s = new_args['s'] or '';
local start = tonumber( new_args['start'] ) or 1;
local plain_flag = str._getBoolean( new_args['plain'] or false );
local pattern = new_args['pattern'] or '';
local match_index = math.floor( tonumber(new_args['match']) or 1 );
local nomatch = new_args['nomatch'];
 
return str._match( s, pattern, start, match_index, plain, nomatch )
end
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu