11--
22-- json.lua
33--
4- -- Copyright (c) 2015 rxi
4+ -- Copyright (c) 2018 rxi
55--
6- -- This library is free software; you can redistribute it and/or modify it
7- -- under the terms of the MIT license. See LICENSE for details.
6+ -- Permission is hereby granted, free of charge, to any person obtaining a copy of
7+ -- this software and associated documentation files (the "Software"), to deal in
8+ -- the Software without restriction, including without limitation the rights to
9+ -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10+ -- of the Software, and to permit persons to whom the Software is furnished to do
11+ -- so, subject to the following conditions:
12+ --
13+ -- The above copyright notice and this permission notice shall be included in all
14+ -- copies or substantial portions of the Software.
15+ --
16+ -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ -- SOFTWARE.
823--
924
1025local json = { _version = " 0.1.0" }
3853
3954local function encode_nil (val )
4055 return " null"
41- end
56+ end
4257
4358
4459local function encode_table (val , stack )
127142
128143local parse
129144
130- local function create_set (...)
145+ local function create_set (...)
131146 local res = {}
132147 for i = 1 , select (" #" , ... ) do
133148 res [ select (i , ... ) ] = true
@@ -234,17 +249,17 @@ local function parse_string(str, i)
234249
235250 elseif x == 34 then -- '"' (end of string)
236251 local s = str :sub (i + 1 , j - 1 )
237- if has_surrogate_escape then
252+ if has_surrogate_escape then
238253 s = s :gsub (" \\ u[dD][89aAbB]..\\ u...." , parse_unicode_escape )
239254 end
240- if has_unicode_escape then
255+ if has_unicode_escape then
241256 s = s :gsub (" \\ u...." , parse_unicode_escape )
242257 end
243258 if has_escape then
244259 s = s :gsub (" \\ ." , escape_char_map_inv )
245260 end
246261 return s , j + 1
247-
262+
248263 else
249264 last = x
250265 end
@@ -282,15 +297,15 @@ local function parse_array(str, i)
282297 local x
283298 i = next_char (str , i , space_chars , true )
284299 -- Empty / end of array?
285- if str :sub (i , i ) == " ]" then
300+ if str :sub (i , i ) == " ]" then
286301 i = i + 1
287302 break
288303 end
289304 -- Read token
290305 x , i = parse (str , i )
291306 res [n ] = x
292307 n = n + 1
293- -- Next token
308+ -- Next token
294309 i = next_char (str , i , space_chars , true )
295310 local chr = str :sub (i , i )
296311 i = i + 1
@@ -308,7 +323,7 @@ local function parse_object(str, i)
308323 local key , val
309324 i = next_char (str , i , space_chars , true )
310325 -- Empty / end of object?
311- if str :sub (i , i ) == " }" then
326+ if str :sub (i , i ) == " }" then
312327 i = i + 1
313328 break
314329 end
0 commit comments