Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into klntsky/serializati…
…on-lib
- Loading branch information
Showing
27 changed files
with
676 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["0","12","-1","1.5","-1.431","1123098123928347023894729384","1\"k\"0","10","10E-20","-2.5324e-23",null,false,true,"10"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"10":"10.5","1 0":null,"1\"0":"10","2\"0":"-20e-20","nest":[{"a":"10e-20"},{"b":false}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"a":"\\\\","b":"123"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[0,12,-1,1.5,-1.431,1123098123928347023894729384,"1\"k\"0","10",10E-20,-2.5324e-23,null,false,true,10] |
10 changes: 10 additions & 0 deletions
10
fixtures/test/parsing/json_stringify_numbers/input/t2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"10": 10.5, | ||
"1 0": null, | ||
"1\"0": 10, | ||
"2\"0": "-20e-20", | ||
"nest": [ | ||
{"a":10e-20}, | ||
{"b":false} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"a":"\\\\","b":123} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
// jsonTurnNumbersToStrings :: String -> String | ||
exports.jsonTurnNumbersToStrings = (str) => { | ||
const s = String(str); | ||
|
||
var arr = []; | ||
var prev_in_number = false; | ||
var in_number = false; | ||
var in_string = false; | ||
var escaped = -1; | ||
|
||
for (var i = 0, n = s.length; i < n; ++i) { | ||
const c = s[i]; | ||
// set the escape flag | ||
if (in_string && escaped!=i){ | ||
if (c == "\\"){ | ||
escaped = i+1; | ||
} | ||
} | ||
// set in_string flag | ||
if (c == '"' && escaped!=i) { | ||
in_string = !in_string; | ||
} | ||
// set in_number flag and quote numbers | ||
if(!in_string){ | ||
if (c >= '0' && c <= '9' || c == '-') { | ||
in_number=true; | ||
} | ||
// assuming a number can only end with: | ||
if (c == ',' || c == '}' || c == ']' || /\s/.test(c)){ | ||
if(in_number){ | ||
arr.push("\""); | ||
} | ||
in_number=false; | ||
} | ||
if(in_number){ | ||
if(!prev_in_number){ | ||
arr.push("\""); | ||
} | ||
} | ||
prev_in_number = in_number; | ||
} | ||
// push char if in string or is not a whitespace | ||
if(in_string || !/\s/.test(c)){ | ||
arr.push(c); | ||
} | ||
} | ||
// simple number case - close with quote | ||
if (!in_string && in_number){ | ||
arr.push("\""); | ||
} | ||
return arr.join(''); | ||
}; |
Oops, something went wrong.