* Skip BOM for inifiles Mantis #24385

git-svn-id: trunk@26865 -
This commit is contained in:
marco 2014-02-24 11:00:48 +00:00
parent 96c24dcccc
commit 526d84fd47

View File

@ -185,6 +185,7 @@ type
FStream: TStream; FStream: TStream;
FCacheUpdates: Boolean; FCacheUpdates: Boolean;
FDirty : Boolean; FDirty : Boolean;
FBOM : String;
procedure FillSectionList(AStrings: TStrings); procedure FillSectionList(AStrings: TStrings);
Procedure DeleteSection(ASection : TIniFileSection); Procedure DeleteSection(ASection : TIniFileSection);
Procedure MaybeDeleteSection(ASection : TIniFileSection); Procedure MaybeDeleteSection(ASection : TIniFileSection);
@ -698,6 +699,7 @@ constructor TIniFile.Create(const AFileName: string; AEscapeLineFeeds : Boolean
var var
slLines: TStringList; slLines: TStringList;
begin begin
FBOM := '';
If Not (self is TMemIniFile) then If Not (self is TMemIniFile) then
StripQuotes:=True; StripQuotes:=True;
inherited Create(AFileName,AEscapeLineFeeds); inherited Create(AFileName,AEscapeLineFeeds);
@ -719,6 +721,7 @@ constructor TIniFile.Create(AStream: TStream; AEscapeLineFeeds : Boolean = False
var var
slLines: TStringList; slLines: TStringList;
begin begin
FBOM := '';
inherited Create('',AEscapeLineFeeds); inherited Create('',AEscapeLineFeeds);
FStream := AStream; FStream := AStream;
slLines := TStringList.Create; slLines := TStringList.Create;
@ -743,6 +746,9 @@ begin
end; end;
procedure TIniFile.FillSectionList(AStrings: TStrings); procedure TIniFile.FillSectionList(AStrings: TStrings);
const
Utf8Bom = #$EF#$BB#$BF; { Die einzelnen BOM Typen }
var var
i,j: integer; i,j: integer;
sLine, sIdent, sValue: string; sLine, sIdent, sValue: string;
@ -777,6 +783,11 @@ begin
FSectionList.Clear; FSectionList.Clear;
if FEscapeLineFeeds then if FEscapeLineFeeds then
RemoveBackslashes; RemoveBackslashes;
if (AStrings.Count > 0) and (copy(AStrings.Strings[0],1,Length(Utf8Bom)) = Utf8Bom) then
begin
FBOM := Utf8Bom;
AStrings.Strings[0] := copy(AStrings.Strings[0],Length(Utf8Bom)+1,Length(AStrings.Strings[0]));
end;
for i := 0 to AStrings.Count-1 do begin for i := 0 to AStrings.Count-1 do begin
sLine := Trim(AStrings[i]); sLine := Trim(AStrings[i]);
if sLine > '' then if sLine > '' then
@ -1034,6 +1045,8 @@ begin
if (i < FSectionList.Count-1) and not IsComment(Name) then if (i < FSectionList.Count-1) and not IsComment(Name) then
slLines.Add(''); slLines.Add('');
end; end;
if slLines.Count > 0 then
slLines.Strings[0] := FBOM + slLines.Strings[0];
if FFileName > '' then if FFileName > '' then
begin begin
D:=ExtractFilePath(FFileName); D:=ExtractFilePath(FFileName);