Commit ab827594 authored by Pierre Ynard's avatar Pierre Ynard

lua: fix sign errors in us_tonumber()

(cherry picked from commit 541ccdc6134a6340afcf9e0f9612f2a86e733ed6)
Signed-off-by: default avatarPierre Ynard <linkfanel@yahoo.fr>
parent 5c1cb49e
...@@ -49,14 +49,23 @@ end ...@@ -49,14 +49,23 @@ end
-- tonumber() for decimals number, using a dot as decimal separator -- tonumber() for decimals number, using a dot as decimal separator
-- regardless of the system locale -- regardless of the system locale
function us_tonumber(str) function us_tonumber(str)
local i, d = string.match(str, "([+-]?%d*)%.?(%d*)") local s, i, d = string.match(str, "^([+-]?)(%d*)%.?(%d*)$")
if i == nil or i == "" then if not s or not i or not d then
return nil
end
if s == "-" then
s = -1
else
s = 1
end
if i == "" then
i = "0" i = "0"
end end
if d == nil or d == "" then if d == nil or d == "" then
d = "0" d = "0"
end end
return tonumber(i) + tonumber(d)/(10^string.len(d)) return s * (tonumber(i) + tonumber(d)/(10^string.len(d)))
end end
-- strip leading and trailing spaces -- strip leading and trailing spaces
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment