Jump to content

Module:StringFailures

Unchecked
From Wikipedia

Documentation for this module may be created at Module:StringFailures/doc

--[[Trying to get a reproducible case for string parsing failures]]

-- Dear Dragons flight, I am Rical and I am sorry if I disturb you in your work.
-- Searching other things, I seen many "Script error" and tried to understand them.
-- Many time in my modules, I add track of execution to understand the issues.
-- I your case the compiler seems convert s to a string which give an error, then I correct it by tonumber(s)
-- Also to help to verify the find, I add to output the first and last positions and the number of findings.
-- To work fastly, I also write your test page name in "Preview page with this template"
-- and after each code change, I try it by cliking "Show preview" below the edit window.

p = {};

function p.test( frame )
    input = frame.args.input or frame.args[1];
    local output = '';  
    output = output .. 'Input length=' .. tostring( string.len( input ) )
    
--  for k = 1,20 do        
        local s = 1;
        local N = 0;
        local first = 0;
        local last = 0;
        repeat
            s = tonumber(s)
            s = string.find(input,"%[%[User:([^/]-)[|%]]",s)
        --  output = output .. " s=" .. tostring( s ) -- track all finds
            if first == 0 then first = s end
            if s ~= nil then last = s end
            if s == nil then s = -2 end
            s = s + 1
            N = N + 1
        until s == -1;
        output = output .. " first=" .. tostring( first ) .. " last=" .. tostring( last ) .. " N=" .. tostring( N )
--  end

--[==[ gmatch error case
    for k = 1,20 do        
        for tt in string.gmatch(input,"%[%[User:([^/]-)[|%]]") do
            --Do nothing
        end
        input = 'b' .. input .. 'b';
    end
]==]
    output = output .. "\n";
    return output;
end

return p;