mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 01:09:06 +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;
|
SysUtils, Classes, fpjson, jsonscanner, jsonparser;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
DefaultJSONOptions = [joUTF8,joComments];
|
DefaultJSONOptions = [joUTF8,joComments,joBOMCheck];
|
||||||
|
|
||||||
type
|
type
|
||||||
EJSONConfigError = class(Exception);
|
EJSONConfigError = class(Exception);
|
||||||
|
@ -51,7 +51,7 @@ type
|
|||||||
|
|
||||||
EScannerError = class(EParserError);
|
EScannerError = class(EParserError);
|
||||||
|
|
||||||
TJSONOption = (joUTF8,joStrict,joComments,joIgnoreTrailingComma,joIgnoreDuplicates);
|
TJSONOption = (joUTF8,joStrict,joComments,joIgnoreTrailingComma,joIgnoreDuplicates,joBOMCheck);
|
||||||
TJSONOptions = set of TJSONOption;
|
TJSONOptions = set of TJSONOption;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
@ -141,10 +141,26 @@ end;
|
|||||||
|
|
||||||
constructor TJSONScanner.Create(Source: TStream; AOptions: TJSONOptions);
|
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
|
Var
|
||||||
S : RawByteString;
|
S : RawByteString;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
if (joBOMCheck in aOptions) then
|
||||||
|
SkipStreamBom;
|
||||||
S:='';
|
S:='';
|
||||||
SetLength(S,Source.Size-Source.Position);
|
SetLength(S,Source.Size-Source.Position);
|
||||||
if Length(S)>0 then
|
if Length(S)>0 then
|
||||||
|
Loading…
Reference in New Issue
Block a user