mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 21:49:15 +02:00
parent
53eca29309
commit
37129e44bc
@ -331,6 +331,7 @@ Procedure TBaseJSONReader.ParseObject;
|
|||||||
Var
|
Var
|
||||||
T : TJSONtoken;
|
T : TJSONtoken;
|
||||||
LastComma : Boolean;
|
LastComma : Boolean;
|
||||||
|
S : TJSONStringType;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
LastComma:=False;
|
LastComma:=False;
|
||||||
@ -340,7 +341,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
If (T<>tkString) and (T<>tkIdentifier) then
|
If (T<>tkString) and (T<>tkIdentifier) then
|
||||||
DoError(SErrExpectedElementName);
|
DoError(SErrExpectedElementName);
|
||||||
KeyValue(CurrentTokenString);
|
S:=CurrentTokenString;
|
||||||
|
KeyValue(S);
|
||||||
|
// Writeln(S);
|
||||||
T:=GetNextToken;
|
T:=GetNextToken;
|
||||||
If (T<>tkColon) then
|
If (T<>tkColon) then
|
||||||
DoError(SErrExpectedColon);
|
DoError(SErrExpectedColon);
|
||||||
|
@ -190,7 +190,16 @@ end;
|
|||||||
|
|
||||||
function TJSONScanner.FetchToken: TJSONToken;
|
function TJSONScanner.FetchToken: TJSONToken;
|
||||||
|
|
||||||
|
(*
|
||||||
|
procedure dumpcurrent;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Writeln('Start of line : ',FCurLine);
|
||||||
|
Writeln('Cur pos : ',FCurPos);
|
||||||
|
Writeln('Start of token : ',FTokenstr);
|
||||||
|
Writeln('End of line : ',FTokenstr);
|
||||||
|
end;
|
||||||
|
*)
|
||||||
function FetchLine: Boolean;
|
function FetchLine: Boolean;
|
||||||
|
|
||||||
|
|
||||||
@ -203,7 +212,7 @@ function TJSONScanner.FetchToken: TJSONToken;
|
|||||||
While Not (FCurPos^ in [#0,#10,#13]) do
|
While Not (FCurPos^ in [#0,#10,#13]) do
|
||||||
Inc(FCurPos);
|
Inc(FCurPos);
|
||||||
FEOL:=FCurPos;
|
FEOL:=FCurPos;
|
||||||
if (FCurPos^<>#0) then
|
While (FCurPos^<>#0) and (FCurPos^ in [#10,#13]) do
|
||||||
begin
|
begin
|
||||||
if (FCurPos^=#13) and (FCurPos[1]=#10) then
|
if (FCurPos^=#13) and (FCurPos[1]=#10) then
|
||||||
Inc(FCurPos); // Skip CR-LF
|
Inc(FCurPos); // Skip CR-LF
|
||||||
@ -211,7 +220,7 @@ function TJSONScanner.FetchToken: TJSONToken;
|
|||||||
Inc(FCurRow); // Increase line index
|
Inc(FCurRow); // Increase line index
|
||||||
end;
|
end;
|
||||||
// Len:=FEOL-FTokenStr;
|
// Len:=FEOL-FTokenStr;
|
||||||
// FTokenStr:=PAnsiChar(FCurLine);
|
// FTokenStr:=FCurPos;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -251,13 +260,14 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
if (FTokenStr = nil) or (FTokenStr=FEOL) then
|
if (FTokenStr = nil) or (FTokenStr=FEOL) then
|
||||||
|
begin
|
||||||
if not FetchLine then
|
if not FetchLine then
|
||||||
begin
|
begin
|
||||||
Result := tkEOF;
|
Result := tkEOF;
|
||||||
FCurToken := Result;
|
FCurToken := Result;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
FCurTokenString := '';
|
FCurTokenString := '';
|
||||||
case FTokenStr^ of
|
case FTokenStr^ of
|
||||||
#0: // Empty line
|
#0: // Empty line
|
||||||
@ -269,13 +279,16 @@ begin
|
|||||||
begin
|
begin
|
||||||
Result := tkWhitespace;
|
Result := tkWhitespace;
|
||||||
repeat
|
repeat
|
||||||
Inc(FTokenStr);
|
if FTokenStr = FEOL then
|
||||||
if FTokenStr[0] = #0 then
|
|
||||||
if not FetchLine then
|
|
||||||
begin
|
begin
|
||||||
|
if not FetchLine then
|
||||||
|
begin
|
||||||
FCurToken := Result;
|
FCurToken := Result;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Inc(FTokenStr);
|
||||||
until not (FTokenStr[0] in [#9, ' ']);
|
until not (FTokenStr[0] in [#9, ' ']);
|
||||||
end;
|
end;
|
||||||
'"','''':
|
'"','''':
|
||||||
@ -453,11 +466,12 @@ begin
|
|||||||
Inc(FTokenStr);
|
Inc(FTokenStr);
|
||||||
Case FTokenStr^ of
|
Case FTokenStr^ of
|
||||||
'/' : begin
|
'/' : begin
|
||||||
SectionLength := Length(FCurLine)- (FTokenStr - PChar(FCurLine));
|
|
||||||
Inc(FTokenStr);
|
|
||||||
FCurTokenString:='';
|
FCurTokenString:='';
|
||||||
SetString(FCurTokenString, FTokenStr, SectionLength);
|
Inc(FTokenStr);
|
||||||
Fetchline;
|
TokenStart:=FTokenStr;
|
||||||
|
SectionLength := PChar(FEOL)-TokenStart;
|
||||||
|
SetString(FCurTokenString, TokenStart, SectionLength);
|
||||||
|
FTokenStr:=FCurPos;
|
||||||
end;
|
end;
|
||||||
'*' :
|
'*' :
|
||||||
begin
|
begin
|
||||||
|
@ -70,6 +70,9 @@ type
|
|||||||
Procedure TestHandlerResult;
|
Procedure TestHandlerResult;
|
||||||
Procedure TestHandlerResultStream;
|
Procedure TestHandlerResultStream;
|
||||||
Procedure TestEmptyLine;
|
Procedure TestEmptyLine;
|
||||||
|
Procedure TestStartEmptyLine;
|
||||||
|
Procedure TestObjectEmptyLine;
|
||||||
|
Procedure TestCommentLine;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -564,6 +567,90 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestParser.TestStartEmptyLine;
|
||||||
|
|
||||||
|
// Bug ID 37352: case 1
|
||||||
|
|
||||||
|
const
|
||||||
|
ENDLINE = #$0d#$0a;
|
||||||
|
|
||||||
|
Const
|
||||||
|
MyJSON = ENDLINE+
|
||||||
|
'{'+ENDLINE+
|
||||||
|
'"version":100,'+ENDLINE+
|
||||||
|
// '//comment'+ENDLINE+
|
||||||
|
'"value":200'+ENDLINE+
|
||||||
|
'}'+ENDLINE;
|
||||||
|
|
||||||
|
var
|
||||||
|
J : TJSONData;
|
||||||
|
|
||||||
|
begin
|
||||||
|
With TJSONParser.Create(MyJSON,[joComments]) do
|
||||||
|
Try
|
||||||
|
J:=Parse;
|
||||||
|
J.Free;
|
||||||
|
Finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestParser.TestObjectEmptyLine;
|
||||||
|
|
||||||
|
// Bug ID 37352: case 2
|
||||||
|
|
||||||
|
const
|
||||||
|
ENDLINE = #$0d#$0a;
|
||||||
|
|
||||||
|
|
||||||
|
Const
|
||||||
|
MyJSON = '{'+ENDLINE+
|
||||||
|
''+ENDLINE+
|
||||||
|
'"version":100, //comment'+ENDLINE+
|
||||||
|
'"value":200'+ENDLINE+
|
||||||
|
'}'+ENDLINE;
|
||||||
|
var
|
||||||
|
J : TJSONData;
|
||||||
|
|
||||||
|
begin
|
||||||
|
With TJSONParser.Create(MyJSON,[joComments]) do
|
||||||
|
Try
|
||||||
|
J:=Parse;
|
||||||
|
J.Free;
|
||||||
|
Finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestParser.TestCommentLine;
|
||||||
|
|
||||||
|
// Bug ID 37352: case 3
|
||||||
|
|
||||||
|
const
|
||||||
|
ENDLINE = #$0d#$0a;
|
||||||
|
|
||||||
|
|
||||||
|
Const
|
||||||
|
MyJSON =
|
||||||
|
ENDLINE+
|
||||||
|
'{'+ENDLINE+
|
||||||
|
'"version":100, //comment'+ENDLINE+
|
||||||
|
'"value":200'+ENDLINE+
|
||||||
|
'}'+ENDLINE;
|
||||||
|
|
||||||
|
var
|
||||||
|
J : TJSONData;
|
||||||
|
|
||||||
|
begin
|
||||||
|
With TJSONParser.Create(MyJSON,[joComments]) do
|
||||||
|
Try
|
||||||
|
J:=Parse;
|
||||||
|
J.Free;
|
||||||
|
Finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestParser.DoTestError(S : String; Options : TJSONOptions = DefaultOpts);
|
procedure TTestParser.DoTestError(S : String; Options : TJSONOptions = DefaultOpts);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
|
Loading…
Reference in New Issue
Block a user