|
@@ -83,15 +83,13 @@ end;
|
|
|
Function TStrings.GetSkipLastLineBreak : Boolean;
|
|
|
|
|
|
begin
|
|
|
- CheckSpecialChars;
|
|
|
- Result:=FSkipLastLineBreak;
|
|
|
+ Result:=not TrailingLineBreak;
|
|
|
end;
|
|
|
|
|
|
procedure TStrings.SetSkipLastLineBreak(const AValue : Boolean);
|
|
|
|
|
|
begin
|
|
|
- CheckSpecialChars;
|
|
|
- FSkipLastLineBreak:=AValue;
|
|
|
+ TrailingLineBreak:=not AValue;
|
|
|
end;
|
|
|
|
|
|
Function TStrings.GetLBS : TTextLineBreakStyle;
|
|
@@ -194,6 +192,19 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+function TStrings.GetLineBreakCharLBS: string;
|
|
|
+begin
|
|
|
+ CheckSpecialChars;
|
|
|
+ if FLineBreak<>sLineBreak then
|
|
|
+ Result:=FLineBreak
|
|
|
+ else
|
|
|
+ Case FLBS of
|
|
|
+ tlbsLF : Result:=#10;
|
|
|
+ tlbsCRLF : Result:=#13#10;
|
|
|
+ tlbsCR : Result:=#13;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
function TStrings.GetMissingNameValueSeparatorAction: TMissingNameValueSeparatorAction;
|
|
|
begin
|
|
|
CheckSpecialChars;
|
|
@@ -446,9 +457,24 @@ begin
|
|
|
GetNameValue(Index,Result,V);
|
|
|
end;
|
|
|
|
|
|
+function TStrings.GetStrictDelimiter: Boolean;
|
|
|
+begin
|
|
|
+ Result:=soStrictDelimiter in FOptions;
|
|
|
+end;
|
|
|
+
|
|
|
function TStrings.GetTrailingLineBreak: Boolean;
|
|
|
begin
|
|
|
- Result:=Not SkipLastLineBreak;
|
|
|
+ Result:=soTrailingLineBreak in FOptions;
|
|
|
+end;
|
|
|
+
|
|
|
+function TStrings.GetUseLocale: Boolean;
|
|
|
+begin
|
|
|
+ Result:=soUseLocale in FOptions;
|
|
|
+end;
|
|
|
+
|
|
|
+function TStrings.GetWriteBOM: Boolean;
|
|
|
+begin
|
|
|
+ Result:=soWriteBOM in FOptions;
|
|
|
end;
|
|
|
|
|
|
Function TStrings.GetValue(const Name: string): string;
|
|
@@ -506,7 +532,7 @@ Procedure TStrings.SetDelimitedText(const AValue: string);
|
|
|
|
|
|
begin
|
|
|
CheckSpecialChars;
|
|
|
- DoSetDelimitedText(aValue,True,FStrictDelimiter,FQuoteChar,FDelimiter);
|
|
|
+ DoSetDelimitedText(aValue,True,StrictDelimiter,FQuoteChar,FDelimiter);
|
|
|
end;
|
|
|
|
|
|
Procedure TStrings.DoSetDelimitedText(const AValue: string; DoClear,aStrictDelimiter : Boolean; aQuoteChar,aDelimiter : Char);
|
|
@@ -639,9 +665,36 @@ Procedure TStrings.SetStringsAdapter(const Value: IStringsAdapter);
|
|
|
begin
|
|
|
end;
|
|
|
|
|
|
+procedure TStrings.SetStrictDelimiter(AValue: Boolean);
|
|
|
+begin
|
|
|
+ if AValue then
|
|
|
+ Include(FOptions,soStrictDelimiter)
|
|
|
+ else
|
|
|
+ Exclude(FOptions,soStrictDelimiter);
|
|
|
+end;
|
|
|
+
|
|
|
procedure TStrings.SetTrailingLineBreak(AValue: Boolean);
|
|
|
begin
|
|
|
- SkipLastLineBreak:=Not aValue;
|
|
|
+ if AValue then
|
|
|
+ Include(FOptions,soTrailingLineBreak)
|
|
|
+ else
|
|
|
+ Exclude(FOptions,soTrailingLineBreak);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TStrings.SetUseLocale(AValue: Boolean);
|
|
|
+begin
|
|
|
+ if AValue then
|
|
|
+ Include(FOptions,soUseLocale)
|
|
|
+ else
|
|
|
+ Exclude(FOptions,soUseLocale);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TStrings.SetWriteBOM(AValue: Boolean);
|
|
|
+begin
|
|
|
+ if AValue then
|
|
|
+ Include(FOptions,soWriteBOM)
|
|
|
+ else
|
|
|
+ Exclude(FOptions,soWriteBOM);
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -688,6 +741,13 @@ end;
|
|
|
|
|
|
|
|
|
|
|
|
+function TStrings.CompareStrings(const s1,s2 : string) : Integer;
|
|
|
+begin
|
|
|
+ Result := DoCompareText(s1, s2);
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
procedure TStrings.DefineProperties(Filer: TFiler);
|
|
|
var
|
|
|
HasData: Boolean;
|
|
@@ -739,16 +799,8 @@ Var P : Pchar;
|
|
|
S,NL : String;
|
|
|
|
|
|
begin
|
|
|
- CheckSpecialChars;
|
|
|
+ NL:=GetLineBreakCharLBS;
|
|
|
// Determine needed place
|
|
|
- if FLineBreak<>sLineBreak then
|
|
|
- NL:=FLineBreak
|
|
|
- else
|
|
|
- Case FLBS of
|
|
|
- tlbsLF : NL:=#10;
|
|
|
- tlbsCRLF : NL:=#13#10;
|
|
|
- tlbsCR : NL:=#13;
|
|
|
- end;
|
|
|
L:=0;
|
|
|
NLS:=Length(NL);
|
|
|
For I:=0 to count-1 do
|
|
@@ -946,7 +998,7 @@ end;
|
|
|
procedure TStrings.AddDelimitedText(const S: String);
|
|
|
begin
|
|
|
CheckSpecialChars;
|
|
|
- DoSetDelimitedText(S,False,FStrictDelimiter,FQuoteChar,FDelimiter);
|
|
|
+ DoSetDelimitedText(S,False,StrictDelimiter,FQuoteChar,FDelimiter);
|
|
|
end;
|
|
|
|
|
|
Procedure TStrings.SetUpdateState(Updating: Boolean);
|
|
@@ -972,7 +1024,7 @@ begin
|
|
|
inherited Create;
|
|
|
FDefaultEncoding:=TEncoding.Default;
|
|
|
FEncoding:=nil;
|
|
|
- FWriteBOM:=True;
|
|
|
+ FOptions := [soTrailingLineBreak,soUseLocale,soPreserveBOM];
|
|
|
FAlwaysQuote:=False;
|
|
|
end;
|
|
|
|
|
@@ -1086,7 +1138,7 @@ begin
|
|
|
FNameValueSeparator:=S.FNameValueSeparator;
|
|
|
FLBS:=S.FLBS;
|
|
|
FLineBreak:=S.FLineBreak;
|
|
|
- FWriteBOM:=S.FWriteBOM;
|
|
|
+ FOptions:=S.FOptions;
|
|
|
DefaultEncoding:=S.DefaultEncoding;
|
|
|
SetEncoding(S.Encoding);
|
|
|
AddStrings(S);
|
|
@@ -1181,7 +1233,10 @@ end;
|
|
|
|
|
|
Function TStrings.DoCompareText(const s1,s2 : string) : PtrInt;
|
|
|
begin
|
|
|
- result:=CompareText(s1,s2);
|
|
|
+ if UseLocale then
|
|
|
+ result:=AnsiCompareText(s1,s2)
|
|
|
+ else
|
|
|
+ result:=CompareText(s1,s2);
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -1342,6 +1397,8 @@ begin
|
|
|
finally
|
|
|
EndUpdate;
|
|
|
end;
|
|
|
+ if soPreserveBOM in FOptions then
|
|
|
+ WriteBOM:=False;
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -1376,6 +1433,8 @@ begin
|
|
|
SetLength(Buffer,BufLen-BufDelta+BytesRead);
|
|
|
PreambleLength:=TEncoding.GetBufferEncoding(Buffer,AEncoding,FDefaultEncoding);
|
|
|
T:=AEncoding.GetAnsiString(Buffer,PreambleLength,Length(Buffer)-PreambleLength);
|
|
|
+ if soPreserveBOM in FOptions then
|
|
|
+ WriteBOM:=PreambleLength>0;
|
|
|
SetEncoding(AEncoding);
|
|
|
SetLength(Buffer,0);
|
|
|
SetTextStr(T);
|
|
@@ -1443,6 +1502,21 @@ end;
|
|
|
|
|
|
|
|
|
|
|
|
+Procedure TStrings.SaveToFile(const FileName: string; IgnoreEncoding : Boolean);
|
|
|
+
|
|
|
+Var TheStream : TFileStream;
|
|
|
+
|
|
|
+begin
|
|
|
+ TheStream:=TFileStream.Create(FileName,fmCreate);
|
|
|
+ try
|
|
|
+ SaveToStream(TheStream, IgnoreEncoding);
|
|
|
+ finally
|
|
|
+ TheStream.Free;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Procedure TStrings.SaveToFile(const FileName: string; AEncoding: TEncoding);
|
|
|
|
|
|
Var TheStream : TFileStream;
|
|
@@ -1459,17 +1533,34 @@ end;
|
|
|
|
|
|
|
|
|
Procedure TStrings.SaveToStream(Stream: TStream);
|
|
|
+begin
|
|
|
+ SaveToStream(Stream,False)
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+Procedure TStrings.SaveToStream(Stream: TStream; IgnoreEncoding: Boolean);
|
|
|
Var
|
|
|
- S : String;
|
|
|
+ I,L,NLS : SizeInt;
|
|
|
+ S,NL : String;
|
|
|
+
|
|
|
begin
|
|
|
- if Encoding<>nil then
|
|
|
- SaveToStream(Stream,Encoding)
|
|
|
- else
|
|
|
- begin
|
|
|
- S:=Text;
|
|
|
- if S = '' then Exit;
|
|
|
- Stream.WriteBuffer(Pointer(S)^,Length(S));
|
|
|
- end;
|
|
|
+ if not IgnoreEncoding then
|
|
|
+ begin
|
|
|
+ SaveToStream(Stream,FEncoding);
|
|
|
+ Exit;
|
|
|
+ end;
|
|
|
+ NL:=GetLineBreakCharLBS;
|
|
|
+ NLS:=Length(NL)*SizeOf(Char);
|
|
|
+ For i:=0 To count-1 do
|
|
|
+ begin
|
|
|
+ S:=Strings[I];
|
|
|
+ L:=Length(S);
|
|
|
+ if L<>0 then
|
|
|
+ Stream.WriteBuffer(S[1], L*SizeOf(Char));
|
|
|
+ if (I<Count-1) or Not SkipLastLineBreak then
|
|
|
+ Stream.WriteBuffer(NL[1], NLS);
|
|
|
+ end;
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -1477,20 +1568,34 @@ end;
|
|
|
|
|
|
Procedure TStrings.SaveToStream(Stream: TStream; AEncoding: TEncoding);
|
|
|
|
|
|
-Var B : TBytes;
|
|
|
+Var B,BNL : TBytes;
|
|
|
+ NL,S: string;
|
|
|
+ i,BNLS: SizeInt;
|
|
|
|
|
|
begin
|
|
|
if AEncoding=nil then
|
|
|
AEncoding:=FDefaultEncoding;
|
|
|
- if FWriteBOM then
|
|
|
+ if WriteBOM then
|
|
|
begin
|
|
|
B:=AEncoding.GetPreamble;
|
|
|
if Length(B)>0 then
|
|
|
Stream.WriteBuffer(B[0],Length(B));
|
|
|
end;
|
|
|
- B:=AEncoding.GetAnsiBytes(Text);
|
|
|
- if Length(B)>0 then
|
|
|
- Stream.WriteBuffer(B[0],Length(B));
|
|
|
+
|
|
|
+ NL := GetLineBreakCharLBS;
|
|
|
+ BNL:=AEncoding.GetAnsiBytes(NL);
|
|
|
+ BNLS:=Length(BNL);
|
|
|
+ For i:=0 To count-1 do
|
|
|
+ begin
|
|
|
+ S:=Strings[I];
|
|
|
+ if S<>'' then
|
|
|
+ begin
|
|
|
+ B:=AEncoding.GetAnsiBytes(S);
|
|
|
+ Stream.WriteBuffer(B[0],Length(B));
|
|
|
+ end;
|
|
|
+ if (I<Count-1) or Not SkipLastLineBreak then
|
|
|
+ Stream.WriteBuffer(BNL[0],BNLS);
|
|
|
+ end;
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -1894,15 +1999,18 @@ end;
|
|
|
function TStringList.DoCompareText(const s1, s2: string): PtrInt;
|
|
|
begin
|
|
|
if FCaseSensitive then
|
|
|
- result:=AnsiCompareStr(s1,s2)
|
|
|
- else
|
|
|
- result:=AnsiCompareText(s1,s2);
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-function TStringList.CompareStrings(const s1,s2 : string) : Integer;
|
|
|
-begin
|
|
|
- Result := DoCompareText(s1, s2);
|
|
|
+ begin
|
|
|
+ if UseLocale then
|
|
|
+ result:=AnsiCompareStr(s1,s2)
|
|
|
+ else
|
|
|
+ result:=CompareStr(s1,s2);
|
|
|
+ end else
|
|
|
+ begin
|
|
|
+ if UseLocale then
|
|
|
+ result:=AnsiCompareText(s1,s2)
|
|
|
+ else
|
|
|
+ result:=CompareText(s1,s2);
|
|
|
+ end;
|
|
|
end;
|
|
|
|
|
|
|