[vlc-commits] lua http: use us_tostring() to fix locale issues with decimals

Pierre Ynard git at videolan.org
Sun Mar 25 05:10:03 CEST 2012


vlc/vlc-2.0 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Sun Mar 25 05:04:40 2012 +0200| [39356457012d8bbd382458ab6619629d8c2744d6] | committer: Pierre Ynard

lua http: use us_tostring() to fix locale issues with decimals

The function is a bit ugly but it's difficult to do this using
pure arithmetic.

Fixes #6378
(cherry picked from commit 1e9dc2967b7bb058d19231740bb64edaa8533ae8)

Signed-off-by: Pierre Ynard <linkfanel at yahoo.fr>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=39356457012d8bbd382458ab6619629d8c2744d6
---

 share/lua/intf/modules/common.lua       |    7 +++++++
 share/lua/intf/modules/httprequests.lua |    3 +++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/share/lua/intf/modules/common.lua b/share/lua/intf/modules/common.lua
index cc6251f..ea1d43b 100644
--- a/share/lua/intf/modules/common.lua
+++ b/share/lua/intf/modules/common.lua
@@ -68,6 +68,13 @@ function us_tonumber(str)
     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
 function strip(str)
     return string.gsub(str, "^%s*(.-)%s*$", "%1")
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index 8ce8995..c060796 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -24,6 +24,7 @@
 
 module("httprequests",package.seeall)
 
+local common = require ("common")
 local dkjson = require ("dkjson")
 
 
@@ -201,6 +202,8 @@ end
 function xmlString(s)
   if (type(s)=="string") then
       return vlc.strings.convert_xml_special_chars(s)
+  elseif (type(s)=="number") then
+      return common.us_tostring(s)
   else
       return tostring(s)
   end



More information about the vlc-commits mailing list