* Allow BOM check

git-svn-id: trunk@48926 -
This commit is contained in:
michael 2021-03-09 11:56:08 +00:00
parent bb97c5ab69
commit b4d37f78ac
2 changed files with 18 additions and 2 deletions

View File

@ -31,7 +31,7 @@ uses
SysUtils, Classes, fpjson, jsonscanner, jsonparser;
Const
DefaultJSONOptions = [joUTF8,joComments];
DefaultJSONOptions = [joUTF8,joComments,joBOMCheck];
type
EJSONConfigError = class(Exception);

View File

@ -51,7 +51,7 @@ type
EScannerError = class(EParserError);
TJSONOption = (joUTF8,joStrict,joComments,joIgnoreTrailingComma,joIgnoreDuplicates);
TJSONOption = (joUTF8,joStrict,joComments,joIgnoreTrailingComma,joIgnoreDuplicates,joBOMCheck);
TJSONOptions = set of TJSONOption;
Const
@ -141,10 +141,26 @@ end;
constructor TJSONScanner.Create(Source: TStream; AOptions: TJSONOptions);
procedure SkipStreamBOM;
Var
OldPos : integer;
Header : array[0..3] of byte;
begin
OldPos := Source.Position;
FillChar(Header, SizeOf(Header), 0);
if Source.Read(Header, 3) = 3 then
if (Header[0]=$EF) and (Header[1]=$BB) and (Header[2]=$BF) then
exit;
Source.Position := OldPos;
end;
Var
S : RawByteString;
begin
if (joBOMCheck in aOptions) then
SkipStreamBom;
S:='';
SetLength(S,Source.Size-Source.Position);
if Length(S)>0 then