跳转到内容

模組:Startswith

维基百科,自由的百科全书

local p = {}
 
function p.startswith(frame)
	local args
	local str
	local second
	local length
	local head
	
	if frame == mw.getCurrentFrame() then
        -- called via #invoke
        args = frame.args
        can_call_parse = true
    else
        -- called from another module
        args = frame
        if type(args) ~= type({}) then args = {frame} end
    end
    
    if args[1] then str = args[1] else str = args['1'] end
    if args['start'] then
    	head = args['start']
    else
    	if args['length'] then
    		length = tonumber(args['length'])
    	else
    		if args[2] then second = args[2] else second = args['2'] end
    		if type(tonumber(second)) == 'number' then length = tonumber(second) else head = second end
    	end
    end
    
    if length then
    	return str:sub(1, length)
    else
    	return str:sub(1, #head) == head
    end
    
end
 
return p