mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 02:26:20 +02:00
* Allow BOM check
git-svn-id: trunk@48926 -
This commit is contained in:
parent
bb97c5ab69
commit
b4d37f78ac
@ -31,7 +31,7 @@ uses
|
||||
SysUtils, Classes, fpjson, jsonscanner, jsonparser;
|
||||
|
||||
Const
|
||||
DefaultJSONOptions = [joUTF8,joComments];
|
||||
DefaultJSONOptions = [joUTF8,joComments,joBOMCheck];
|
||||
|
||||
type
|
||||
EJSONConfigError = class(Exception);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user