mirror of https://gitlab.com/basile.b/dexed.git
fix, JSON loader, skip BOM
This commit is contained in:
parent
2ae5fe3b01
commit
92ba1bcdfa
|
@ -153,14 +153,28 @@ procedure TCEDubProject.loadFromFile(const aFilename: string);
|
|||
var
|
||||
loader: TMemoryStream;
|
||||
parser : TJSONParser;
|
||||
bom: dword = 0;
|
||||
begin
|
||||
loader := TMemoryStream.Create;
|
||||
try
|
||||
fBasePath := extractFilePath(aFilename);
|
||||
fFilename := aFilename;
|
||||
loader.LoadFromFile(fFilename);
|
||||
// skip BOM, this crashes the parser
|
||||
loader.Read(bom, 4);
|
||||
if (bom and $BFBBEF) = $BFBBEF then
|
||||
loader.Position:= 3
|
||||
else if bom = $FFFE0000 then
|
||||
loader.Position:= 4
|
||||
else if bom = $FEFF then
|
||||
loader.Position:= 4
|
||||
else if (bom and $FEFF) = $FEFF then
|
||||
loader.Position:= 2
|
||||
else if (bom and $FFFE) = $FFFE then
|
||||
loader.Position:= 2;
|
||||
//
|
||||
fJSON.Free;
|
||||
parser := TJSONParser.Create(loader);
|
||||
parser := TJSONParser.Create(loader, false);
|
||||
try
|
||||
fJSON := parser.Parse as TJSONObject;
|
||||
finally
|
||||
|
|
Loading…
Reference in New Issue