]> git.sesse.net Git - vlc/blobdiff - share/lua/intf/modules/common.lua
HTTP interface: fix infinite loop
[vlc] / share / lua / intf / modules / common.lua
index ca51344f81f0baaaa8633bac93d0aeb1d8051169..7f2956ccf7394b95cfd48b7e72a2dc12633d2f48 100644 (file)
@@ -49,14 +49,30 @@ 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
+
+-- tostring() for decimals number, using a dot as decimal separator
+-- regardless of the system locale 
+function us_tostring(n)
+    s = tostring(n):gsub(",", ".", 1)
+    return s
 end
 
 -- strip leading and trailing spaces
@@ -134,7 +150,7 @@ function seek(value)
         if string.sub(value,-1) == "%" then
             local number = us_tonumber(string.sub(value,1,-2))
             if number ~= nil then
-                local posPercent = number/100.
+                local posPercent = number/100
                 if string.sub(value,1,1) == "+" or string.sub(value,1,1) == "-" then
                     vlc.var.set(input,"position",vlc.var.get(input,"position") + posPercent)
                 else