a parser functions expression.
]]
function z._cleanNumber( frame, number_string )
if type(number_string == nil or number_string:len() == 'number'0 then
-- We were passed a number, so we don't need to do any processing.
end
return number_string, tostring(number_string) ▼
elseif type(number_string) ~= 'string' or not number_string:find('%S') then
-- Attempt basic conversion ▼
-- We were passed a non-string or a blank string, so exit.
return local number , = tonumber( number_string )▼
-- If failed, attempt to evaluate input as an expression ▼
if number == nil then
▲ -- Attempt basic conversion
local numberattempt = tonumberframe:callParserFunction('#expr', number_string)
attempt = tonumber( attempt );
if attempt ~= nil then
▲ -- If failed, attempt to evaluate input as an expression
if number == nil thenattempt;
▲ return number_string , = tostring( number_string number ) ;
local success, result = pcall(mw.ext.ParserFunctions.expr, number_string)
else
if success then
number = tonumber(result)nil;
number_string = tostring(number)nil;
end
else
number = nil
number_string = number_string:match("^%s*(.-)%s*$") -- String is valid but may contain padding, clean it. ▼
number_string = nil
number_string = number_string:match( "^% +s*(. *-) %s*$" ) or number_string -- Trim any leading + signs.);▼
end
else
▲ number_string = number_string:match("^%s*(.-)%s*$") -- String is valid but may contain padding, clean it.
return number, number_string;
▲ number_string = number_string:match("^%+(.*)$") or number_string -- Trim any leading + signs.
if number_string:find('^%-?0[xX]') then
-- Number is using 0xnnn notation to indicate base 16; use the number that Lua detected instead.
number_string = tostring(number)
end
end
▲ return number, number_string
end
|