Merge pull request #2 from kyl3n/master

@kyl3n Fixed locale floating point character
pull/44/head
alexandro-rezakhani 2021-06-04 11:28:41 -04:00 committed by GitHub
commit 17b308b574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -154,6 +154,8 @@ local space_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 literals = create_set("true", "false", "null")
local locale_character = (string.match(tostring(1/2),'%p')) -- return point decimal or comma decimal according to the locale
local literal_map = {
[ "true" ] = true,
@ -259,14 +261,13 @@ end
local function parse_number(str, i)
local x = next_char(str, i, delim_chars)
local s = str:sub(i, x - 1)
s = s:gsub('[%.%,]',locale_character) -- replace the comma decimal or point decimal with the correct one according to the locale
local n = tonumber(s)
if not n then
decode_error(str, i, "invalid number '" .. s .. "'")
end
return n, x
end
local function parse_literal(str, i)
local x = next_char(str, i, delim_chars)
local word = str:sub(i, x - 1)