Browse Source

Refactor JSON parsing

pull/8/head
Anton Tarasenko 4 years ago
parent
commit
4623b05fce
  1. 23
      sources/Data/JSON/JArray.uc
  2. 26
      sources/Data/JSON/JObject.uc

23
sources/Data/JSON/JArray.uc

@ -547,7 +547,6 @@ public function JSON Clone()
public function bool ParseIntoSelfWith(Parser parser) public function bool ParseIntoSelfWith(Parser parser)
{ {
local int i;
local bool parsingSucceeded; local bool parsingSucceeded;
local Parser.ParserState initState; local Parser.ParserState initState;
local JStorageAtom nextAtom; local JStorageAtom nextAtom;
@ -578,18 +577,32 @@ public function bool ParseIntoSelfWith(Parser parser)
break; break;
} }
parsedAtoms[parsedAtoms.length] = nextAtom; parsedAtoms[parsedAtoms.length] = nextAtom;
parser.Confirm();
} }
HandleParsedAtoms(parsedAtoms, parsingSucceeded);
if (!parsingSucceeded) {
parser.RestoreState(initState);
}
return parsingSucceeded;
}
private function HandleParsedAtoms(
array<JStorageAtom> parsedAtoms,
bool parsingSucceeded)
{
local int i;
if (parsingSucceeded) if (parsingSucceeded)
{ {
for (i = 0; i < parsedAtoms.length; i += 1) { for (i = 0; i < parsedAtoms.length; i += 1) {
data[data.length] = parsedAtoms[i]; data[data.length] = parsedAtoms[i];
} }
return;
}
for (i = 0; i < parsedAtoms.length; i += 1)
{
if (parsedAtoms[i].complexValue != none) {
parsedAtoms[i].complexValue.Destroy();
} }
else {
parser.RestoreState(initState);
} }
return parsingSucceeded;
} }
public function string DisplayWith(JSONDisplaySettings displaySettings) public function string DisplayWith(JSONDisplaySettings displaySettings)

26
sources/Data/JSON/JObject.uc

@ -536,7 +536,6 @@ public function JSON Clone()
public function bool ParseIntoSelfWith(Parser parser) public function bool ParseIntoSelfWith(Parser parser)
{ {
local int i;
local bool parsingSucceeded; local bool parsingSucceeded;
local Parser.ParserState initState; local Parser.ParserState initState;
local JProperty nextProperty; local JProperty nextProperty;
@ -552,7 +551,8 @@ public function bool ParseIntoSelfWith(Parser parser)
while (parser.Ok() && !parser.HasFinished()) while (parser.Ok() && !parser.HasFinished())
{ {
parser.Skip().Confirm(); parser.Skip().Confirm();
if (parser.Match("}").Ok()) { if (parser.Match("}").Ok())
{
parsingSucceeded = true; parsingSucceeded = true;
break; break;
} }
@ -568,18 +568,32 @@ public function bool ParseIntoSelfWith(Parser parser)
break; break;
} }
parsedProperties[parsedProperties.length] = nextProperty; parsedProperties[parsedProperties.length] = nextProperty;
parser.Confirm();
} }
HandleParsedProperties(parsedProperties, parsingSucceeded);
if (!parsingSucceeded) {
parser.RestoreState(initState);
}
return parsingSucceeded;
}
private function HandleParsedProperties(
array<JProperty> parsedProperties,
bool parsingSucceeded)
{
local int i;
if (parsingSucceeded) if (parsingSucceeded)
{ {
for (i = 0; i < parsedProperties.length; i += 1) { for (i = 0; i < parsedProperties.length; i += 1) {
UpdateProperty(parsedProperties[i]); UpdateProperty(parsedProperties[i]);
} }
return;
}
for (i = 0; i < parsedProperties.length; i += 1)
{
if (parsedProperties[i].value.complexValue != none) {
parsedProperties[i].value.complexValue.Destroy();
} }
else {
parser.RestoreState(initState);
} }
return parsingSucceeded;
} }
public function string DisplayWith(JSONDisplaySettings displaySettings) public function string DisplayWith(JSONDisplaySettings displaySettings)

Loading…
Cancel
Save