Jump to content

Module:String and Module:String/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
 
Return always strings
 
Line 44: Line 44:
local new_args = str._getParameters( frame.args, {'s'} )
local new_args = str._getParameters( frame.args, {'s'} )
local s = new_args['s'] or ''
local s = new_args['s'] or ''
return mw.ustring.len( s )
return tostring(mw.ustring.len( s ))
end
end


Line 311: Line 311:


if target_str == '' then
if target_str == '' then
return 1
return '1'
end
end


local start = mw.ustring.find( source_str, target_str, 1, true )
local start = mw.ustring.find( source_str, target_str, 1, true )
if start == nil then
if start == nil then
start = -1
return '-1'
end
end


return start
return tostring(start)
end
end


Line 359: Line 359:


if source_str == '' or pattern == '' then
if source_str == '' or pattern == '' then
return 0
return '0'
end
end


Line 366: Line 366:
local start = mw.ustring.find( source_str, pattern, start_pos, plain )
local start = mw.ustring.find( source_str, pattern, start_pos, plain )
if start == nil then
if start == nil then
start = 0
return '0'
end
end


return start
return tostring(start)
end
end


Line 468: Line 468:
end
end
local _, count = mw.ustring.gsub(source, pattern, '')
local _, count = mw.ustring.gsub(source, pattern, '')
return count
return tostring(count)
end
end