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

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


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Sun Mar 25 05:04:40 2012 +0200| [1e9dc2967b7bb058d19231740bb64edaa8533ae8] | 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

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1e9dc2967b7bb058d19231740bb64edaa8533ae8
---

 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 c8ceb7c..6dea512 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")
 
 
@@ -197,6 +198,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