[vlc-commits] lua: fix sign errors in us_tonumber()
Pierre Ynard
git at videolan.org
Sat Jan 7 19:45:38 CET 2012
vlc/vlc-1.2 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Sat Jan 7 19:36:09 2012 +0100| [ab827594a178fe3e4d3df76d31b7434fd6e76fc3] | committer: Pierre Ynard
lua: fix sign errors in us_tonumber()
(cherry picked from commit 541ccdc6134a6340afcf9e0f9612f2a86e733ed6)
Signed-off-by: Pierre Ynard <linkfanel at yahoo.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.2.git/?a=commit;h=ab827594a178fe3e4d3df76d31b7434fd6e76fc3
---
share/lua/intf/modules/common.lua | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/share/lua/intf/modules/common.lua b/share/lua/intf/modules/common.lua
index ca51344..cc6251f 100644
--- a/share/lua/intf/modules/common.lua
+++ b/share/lua/intf/modules/common.lua
@@ -49,14 +49,23 @@ end
-- tonumber() for decimals number, using a dot as decimal separator
-- regardless of the system locale
function us_tonumber(str)
- local i, d = string.match(str, "([+-]?%d*)%.?(%d*)")
- if i == nil or i == "" then
+ local s, i, d = string.match(str, "^([+-]?)(%d*)%.?(%d*)$")
+ 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"
end
if d == nil or d == "" then
d = "0"
end
- return tonumber(i) + tonumber(d)/(10^string.len(d))
+ return s * (tonumber(i) + tonumber(d)/(10^string.len(d)))
end
-- strip leading and trailing spaces
More information about the vlc-commits
mailing list