mirror of https://github.com/rxi/json.lua.git
replace only comma or decimal in floating point integer
previous version was replacing minus sign in negative numbers in error.pull/20/head
parent
0cbd6c3636
commit
a8d5dc7e9d
6
json.lua
6
json.lua
|
@ -154,7 +154,7 @@ local space_chars = create_set(" ", "\t", "\r", "\n")
|
||||||
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
||||||
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
||||||
local literals = create_set("true", "false", "null")
|
local literals = create_set("true", "false", "null")
|
||||||
local locale_character = (string.match(tostring(tonumber(1.1)),'%p')) -- return the locale punctuation character according to the locale
|
local locale_character = (string.match(tostring(1/2),'%p')) -- return point decimal or comma decimal according to the locale
|
||||||
|
|
||||||
|
|
||||||
local literal_map = {
|
local literal_map = {
|
||||||
|
@ -273,15 +273,13 @@ end
|
||||||
local function parse_number(str, i)
|
local function parse_number(str, i)
|
||||||
local x = next_char(str, i, delim_chars)
|
local x = next_char(str, i, delim_chars)
|
||||||
local s = str:sub(i, x - 1)
|
local s = str:sub(i, x - 1)
|
||||||
s = s:gsub('%p',locale_character) -- replace the locale punctuation character in the string with the correct one
|
s = s:gsub('[%.%,]',locale_character) -- replace the comma decimal or point decimal with the correct one according to the locale
|
||||||
local n = tonumber(s)
|
local n = tonumber(s)
|
||||||
if not n then
|
if not n then
|
||||||
decode_error(str, i, "invalid number '" .. s .. "'")
|
decode_error(str, i, "invalid number '" .. s .. "'")
|
||||||
end
|
end
|
||||||
return n, x
|
return n, x
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function parse_literal(str, i)
|
local function parse_literal(str, i)
|
||||||
local x = next_char(str, i, delim_chars)
|
local x = next_char(str, i, delim_chars)
|
||||||
local word = str:sub(i, x - 1)
|
local word = str:sub(i, x - 1)
|
||||||
|
|
Loading…
Reference in New Issue