mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 22:06:40 +02:00
classes: add TStrings.Options (Delphi-compatibility)
git-svn-id: trunk@43841 -
This commit is contained in:
parent
6796434268
commit
5d58ced92b
@ -610,6 +610,8 @@ type
|
|||||||
TStringsForEachMethod = procedure(const CurrentValue: string) of object;
|
TStringsForEachMethod = procedure(const CurrentValue: string) of object;
|
||||||
TMissingNameValueSeparatorAction = (mnvaValue,mnvaName,mnvaEmpty,mnvaError);
|
TMissingNameValueSeparatorAction = (mnvaValue,mnvaName,mnvaEmpty,mnvaError);
|
||||||
TMissingNameValueSeparatorActions = set of TMissingNameValueSeparatorAction;
|
TMissingNameValueSeparatorActions = set of TMissingNameValueSeparatorAction;
|
||||||
|
TStringsOption = (soStrictDelimiter,soWriteBOM,soTrailingLineBreak,soUseLocale);
|
||||||
|
TStringsOptions = set of TStringsOption;
|
||||||
|
|
||||||
TStrings = class(TPersistent)
|
TStrings = class(TPersistent)
|
||||||
private
|
private
|
||||||
@ -624,16 +626,17 @@ type
|
|||||||
FUpdateCount: Integer;
|
FUpdateCount: Integer;
|
||||||
FAdapter: IStringsAdapter;
|
FAdapter: IStringsAdapter;
|
||||||
FLBS : TTextLineBreakStyle;
|
FLBS : TTextLineBreakStyle;
|
||||||
FSkipLastLineBreak : Boolean;
|
FOptions : TStringsOptions;
|
||||||
FStrictDelimiter : Boolean;
|
|
||||||
FLineBreak : String;
|
FLineBreak : String;
|
||||||
FWriteBOM: Boolean;
|
|
||||||
function GetCommaText: string;
|
function GetCommaText: string;
|
||||||
function GetLineBreakCharLBS: string;
|
function GetLineBreakCharLBS: string;
|
||||||
function GetMissingNameValueSeparatorAction: TMissingNameValueSeparatorAction;
|
function GetMissingNameValueSeparatorAction: TMissingNameValueSeparatorAction;
|
||||||
function GetName(Index: Integer): string;
|
function GetName(Index: Integer): string;
|
||||||
|
function GetStrictDelimiter: Boolean;
|
||||||
function GetTrailingLineBreak: Boolean;
|
function GetTrailingLineBreak: Boolean;
|
||||||
|
function GetUseLocale: Boolean;
|
||||||
function GetValue(const Name: string): string;
|
function GetValue(const Name: string): string;
|
||||||
|
function GetWriteBOM: Boolean;
|
||||||
Function GetLBS : TTextLineBreakStyle;
|
Function GetLBS : TTextLineBreakStyle;
|
||||||
procedure SetDefaultEncoding(const ADefaultEncoding: TEncoding);
|
procedure SetDefaultEncoding(const ADefaultEncoding: TEncoding);
|
||||||
procedure SetEncoding(const AEncoding: TEncoding);
|
procedure SetEncoding(const AEncoding: TEncoding);
|
||||||
@ -642,7 +645,10 @@ type
|
|||||||
procedure SetCommaText(const Value: string);
|
procedure SetCommaText(const Value: string);
|
||||||
procedure SetMissingNameValueSeparatorAction(AValue: TMissingNameValueSeparatorAction);
|
procedure SetMissingNameValueSeparatorAction(AValue: TMissingNameValueSeparatorAction);
|
||||||
procedure SetStringsAdapter(const Value: IStringsAdapter);
|
procedure SetStringsAdapter(const Value: IStringsAdapter);
|
||||||
|
procedure SetStrictDelimiter(AValue: Boolean);
|
||||||
procedure SetTrailingLineBreak(AValue: Boolean);
|
procedure SetTrailingLineBreak(AValue: Boolean);
|
||||||
|
procedure SetUseLocale(AValue: Boolean);
|
||||||
|
procedure SetWriteBOM(AValue: Boolean);
|
||||||
procedure SetValue(const Name, Value: string);
|
procedure SetValue(const Name, Value: string);
|
||||||
procedure SetDelimiter(c:Char);
|
procedure SetDelimiter(c:Char);
|
||||||
procedure SetQuoteChar(c:Char);
|
procedure SetQuoteChar(c:Char);
|
||||||
@ -658,6 +664,7 @@ type
|
|||||||
procedure SetSkipLastLineBreak(const AValue : Boolean);
|
procedure SetSkipLastLineBreak(const AValue : Boolean);
|
||||||
Procedure DoSetDelimitedText(const AValue: string; DoClear,aStrictDelimiter : Boolean; aQuoteChar,aDelimiter : Char);
|
Procedure DoSetDelimitedText(const AValue: string; DoClear,aStrictDelimiter : Boolean; aQuoteChar,aDelimiter : Char);
|
||||||
protected
|
protected
|
||||||
|
function CompareStrings(const s1,s2 : string) : Integer; virtual;
|
||||||
procedure DefineProperties(Filer: TFiler); override;
|
procedure DefineProperties(Filer: TFiler); override;
|
||||||
procedure Error(const Msg: string; Data: Integer);
|
procedure Error(const Msg: string; Data: Integer);
|
||||||
procedure Error(const Msg: pstring; Data: Integer);
|
procedure Error(const Msg: pstring; Data: Integer);
|
||||||
@ -763,18 +770,20 @@ type
|
|||||||
property Names[Index: Integer]: string read GetName;
|
property Names[Index: Integer]: string read GetName;
|
||||||
Property NameValueSeparator : Char Read GetNameValueSeparator Write SetNameValueSeparator;
|
Property NameValueSeparator : Char Read GetNameValueSeparator Write SetNameValueSeparator;
|
||||||
property Objects[Index: Integer]: TObject read GetObject write PutObject;
|
property Objects[Index: Integer]: TObject read GetObject write PutObject;
|
||||||
|
property Options: TStringsOptions read FOptions write FOptions;
|
||||||
property QuoteChar: Char read GetQuoteChar write SetQuoteChar;
|
property QuoteChar: Char read GetQuoteChar write SetQuoteChar;
|
||||||
Property SkipLastLineBreak : Boolean Read GetSkipLastLineBreak Write SetSkipLastLineBreak;
|
Property SkipLastLineBreak : Boolean Read GetSkipLastLineBreak Write SetSkipLastLineBreak;
|
||||||
// Same as SkipLastLineBreak but for Delphi compatibility. Note it has opposite meaning.
|
// Same as SkipLastLineBreak but for Delphi compatibility. Note it has opposite meaning.
|
||||||
Property TrailingLineBreak : Boolean Read GetTrailingLineBreak Write SetTrailingLineBreak;
|
Property TrailingLineBreak : Boolean Read GetTrailingLineBreak Write SetTrailingLineBreak;
|
||||||
Property StrictDelimiter : Boolean Read FStrictDelimiter Write FStrictDelimiter;
|
Property StrictDelimiter : Boolean Read GetStrictDelimiter Write SetStrictDelimiter;
|
||||||
property Strings[Index: Integer]: string read Get write Put; default;
|
property Strings[Index: Integer]: string read Get write Put; default;
|
||||||
property StringsAdapter: IStringsAdapter read FAdapter write SetStringsAdapter;
|
property StringsAdapter: IStringsAdapter read FAdapter write SetStringsAdapter;
|
||||||
property Text: string read GetTextStr write SetTextStr;
|
property Text: string read GetTextStr write SetTextStr;
|
||||||
Property TextLineBreakStyle : TTextLineBreakStyle Read GetLBS Write SetLBS;
|
Property TextLineBreakStyle : TTextLineBreakStyle Read GetLBS Write SetLBS;
|
||||||
|
Property UseLocale : Boolean Read GetUseLocale Write SetUseLocale;
|
||||||
property ValueFromIndex[Index: Integer]: string read GetValueFromIndex write SetValueFromIndex;
|
property ValueFromIndex[Index: Integer]: string read GetValueFromIndex write SetValueFromIndex;
|
||||||
property Values[const Name: string]: string read GetValue write SetValue;
|
property Values[const Name: string]: string read GetValue write SetValue;
|
||||||
property WriteBOM: Boolean read FWriteBOM write FWriteBOM;
|
property WriteBOM: Boolean read GetWriteBOM write SetWriteBOM;
|
||||||
end;
|
end;
|
||||||
TStringsClass = Class of TStrings;
|
TStringsClass = Class of TStrings;
|
||||||
|
|
||||||
@ -833,7 +842,6 @@ type
|
|||||||
procedure InsertItem(Index: Integer; const S: string); virtual;
|
procedure InsertItem(Index: Integer; const S: string); virtual;
|
||||||
procedure InsertItem(Index: Integer; const S: string; O: TObject); virtual;
|
procedure InsertItem(Index: Integer; const S: string; O: TObject); virtual;
|
||||||
Function DoCompareText(const s1,s2 : string) : PtrInt; override;
|
Function DoCompareText(const s1,s2 : string) : PtrInt; override;
|
||||||
function CompareStrings(const s1,s2 : string) : Integer; virtual;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
@ -83,15 +83,13 @@ end;
|
|||||||
Function TStrings.GetSkipLastLineBreak : Boolean;
|
Function TStrings.GetSkipLastLineBreak : Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
CheckSpecialChars;
|
Result:=not TrailingLineBreak;
|
||||||
Result:=FSkipLastLineBreak;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TStrings.SetSkipLastLineBreak(const AValue : Boolean);
|
procedure TStrings.SetSkipLastLineBreak(const AValue : Boolean);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
CheckSpecialChars;
|
TrailingLineBreak:=not AValue;
|
||||||
FSkipLastLineBreak:=AValue;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TStrings.GetLBS : TTextLineBreakStyle;
|
Function TStrings.GetLBS : TTextLineBreakStyle;
|
||||||
@ -459,9 +457,24 @@ begin
|
|||||||
GetNameValue(Index,Result,V);
|
GetNameValue(Index,Result,V);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TStrings.GetStrictDelimiter: Boolean;
|
||||||
|
begin
|
||||||
|
Result:=soStrictDelimiter in FOptions;
|
||||||
|
end;
|
||||||
|
|
||||||
function TStrings.GetTrailingLineBreak: Boolean;
|
function TStrings.GetTrailingLineBreak: Boolean;
|
||||||
begin
|
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;
|
end;
|
||||||
|
|
||||||
Function TStrings.GetValue(const Name: string): string;
|
Function TStrings.GetValue(const Name: string): string;
|
||||||
@ -519,7 +532,7 @@ Procedure TStrings.SetDelimitedText(const AValue: string);
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
CheckSpecialChars;
|
CheckSpecialChars;
|
||||||
DoSetDelimitedText(aValue,True,FStrictDelimiter,FQuoteChar,FDelimiter);
|
DoSetDelimitedText(aValue,True,StrictDelimiter,FQuoteChar,FDelimiter);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure TStrings.DoSetDelimitedText(const AValue: string; DoClear,aStrictDelimiter : Boolean; aQuoteChar,aDelimiter : Char);
|
Procedure TStrings.DoSetDelimitedText(const AValue: string; DoClear,aStrictDelimiter : Boolean; aQuoteChar,aDelimiter : Char);
|
||||||
@ -652,9 +665,36 @@ Procedure TStrings.SetStringsAdapter(const Value: IStringsAdapter);
|
|||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TStrings.SetStrictDelimiter(AValue: Boolean);
|
||||||
|
begin
|
||||||
|
if AValue then
|
||||||
|
Include(FOptions,soStrictDelimiter)
|
||||||
|
else
|
||||||
|
Exclude(FOptions,soStrictDelimiter);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TStrings.SetTrailingLineBreak(AValue: Boolean);
|
procedure TStrings.SetTrailingLineBreak(AValue: Boolean);
|
||||||
begin
|
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;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -701,6 +741,13 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function TStrings.CompareStrings(const s1,s2 : string) : Integer;
|
||||||
|
begin
|
||||||
|
Result := DoCompareText(s1, s2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
procedure TStrings.DefineProperties(Filer: TFiler);
|
procedure TStrings.DefineProperties(Filer: TFiler);
|
||||||
var
|
var
|
||||||
HasData: Boolean;
|
HasData: Boolean;
|
||||||
@ -758,7 +805,7 @@ begin
|
|||||||
NLS:=Length(NL);
|
NLS:=Length(NL);
|
||||||
For I:=0 to count-1 do
|
For I:=0 to count-1 do
|
||||||
L:=L+Length(Strings[I])+NLS;
|
L:=L+Length(Strings[I])+NLS;
|
||||||
if FSkipLastLineBreak then
|
if SkipLastLineBreak then
|
||||||
Dec(L,NLS);
|
Dec(L,NLS);
|
||||||
Setlength(Result,L);
|
Setlength(Result,L);
|
||||||
P:=Pointer(Result);
|
P:=Pointer(Result);
|
||||||
@ -769,7 +816,7 @@ begin
|
|||||||
if L<>0 then
|
if L<>0 then
|
||||||
System.Move(Pointer(S)^,P^,L);
|
System.Move(Pointer(S)^,P^,L);
|
||||||
P:=P+L;
|
P:=P+L;
|
||||||
if (I<Count-1) or Not FSkipLastLineBreak then
|
if (I<Count-1) or Not SkipLastLineBreak then
|
||||||
For L:=1 to NLS do
|
For L:=1 to NLS do
|
||||||
begin
|
begin
|
||||||
P^:=NL[L];
|
P^:=NL[L];
|
||||||
@ -951,7 +998,7 @@ end;
|
|||||||
procedure TStrings.AddDelimitedText(const S: String);
|
procedure TStrings.AddDelimitedText(const S: String);
|
||||||
begin
|
begin
|
||||||
CheckSpecialChars;
|
CheckSpecialChars;
|
||||||
DoSetDelimitedText(S,False,FStrictDelimiter,FQuoteChar,FDelimiter);
|
DoSetDelimitedText(S,False,StrictDelimiter,FQuoteChar,FDelimiter);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure TStrings.SetUpdateState(Updating: Boolean);
|
Procedure TStrings.SetUpdateState(Updating: Boolean);
|
||||||
@ -977,7 +1024,7 @@ begin
|
|||||||
inherited Create;
|
inherited Create;
|
||||||
FDefaultEncoding:=TEncoding.Default;
|
FDefaultEncoding:=TEncoding.Default;
|
||||||
FEncoding:=nil;
|
FEncoding:=nil;
|
||||||
FWriteBOM:=True;
|
FOptions := [soWriteBOM,soTrailingLineBreak,soUseLocale];
|
||||||
FAlwaysQuote:=False;
|
FAlwaysQuote:=False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1091,7 +1138,7 @@ begin
|
|||||||
FNameValueSeparator:=S.FNameValueSeparator;
|
FNameValueSeparator:=S.FNameValueSeparator;
|
||||||
FLBS:=S.FLBS;
|
FLBS:=S.FLBS;
|
||||||
FLineBreak:=S.FLineBreak;
|
FLineBreak:=S.FLineBreak;
|
||||||
FWriteBOM:=S.FWriteBOM;
|
FOptions:=S.FOptions;
|
||||||
DefaultEncoding:=S.DefaultEncoding;
|
DefaultEncoding:=S.DefaultEncoding;
|
||||||
SetEncoding(S.Encoding);
|
SetEncoding(S.Encoding);
|
||||||
AddStrings(S);
|
AddStrings(S);
|
||||||
@ -1186,7 +1233,10 @@ end;
|
|||||||
|
|
||||||
Function TStrings.DoCompareText(const s1,s2 : string) : PtrInt;
|
Function TStrings.DoCompareText(const s1,s2 : string) : PtrInt;
|
||||||
begin
|
begin
|
||||||
result:=CompareText(s1,s2);
|
if UseLocale then
|
||||||
|
result:=AnsiCompareText(s1,s2)
|
||||||
|
else
|
||||||
|
result:=CompareText(s1,s2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1489,7 +1539,7 @@ begin
|
|||||||
L:=Length(S);
|
L:=Length(S);
|
||||||
if L<>0 then
|
if L<>0 then
|
||||||
Stream.WriteBuffer(S[1], L*SizeOf(Char));
|
Stream.WriteBuffer(S[1], L*SizeOf(Char));
|
||||||
if (I<Count-1) or Not FSkipLastLineBreak then
|
if (I<Count-1) or Not SkipLastLineBreak then
|
||||||
Stream.WriteBuffer(NL[1], NLS);
|
Stream.WriteBuffer(NL[1], NLS);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1506,7 +1556,7 @@ Var B,BNL : TBytes;
|
|||||||
begin
|
begin
|
||||||
if AEncoding=nil then
|
if AEncoding=nil then
|
||||||
AEncoding:=FDefaultEncoding;
|
AEncoding:=FDefaultEncoding;
|
||||||
if FWriteBOM then
|
if WriteBOM then
|
||||||
begin
|
begin
|
||||||
B:=AEncoding.GetPreamble;
|
B:=AEncoding.GetPreamble;
|
||||||
if Length(B)>0 then
|
if Length(B)>0 then
|
||||||
@ -1524,7 +1574,7 @@ begin
|
|||||||
B:=AEncoding.GetAnsiBytes(S);
|
B:=AEncoding.GetAnsiBytes(S);
|
||||||
Stream.WriteBuffer(B[0],Length(B));
|
Stream.WriteBuffer(B[0],Length(B));
|
||||||
end;
|
end;
|
||||||
if (I<Count-1) or Not FSkipLastLineBreak then
|
if (I<Count-1) or Not SkipLastLineBreak then
|
||||||
Stream.WriteBuffer(BNL[0],BNLS);
|
Stream.WriteBuffer(BNL[0],BNLS);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1884,15 +1934,18 @@ end;
|
|||||||
function TStringList.DoCompareText(const s1, s2: string): PtrInt;
|
function TStringList.DoCompareText(const s1, s2: string): PtrInt;
|
||||||
begin
|
begin
|
||||||
if FCaseSensitive then
|
if FCaseSensitive then
|
||||||
result:=AnsiCompareStr(s1,s2)
|
begin
|
||||||
else
|
if UseLocale then
|
||||||
result:=AnsiCompareText(s1,s2);
|
result:=AnsiCompareStr(s1,s2)
|
||||||
end;
|
else
|
||||||
|
result:=CompareStr(s1,s2);
|
||||||
|
end else
|
||||||
function TStringList.CompareStrings(const s1,s2 : string) : Integer;
|
begin
|
||||||
begin
|
if UseLocale then
|
||||||
Result := DoCompareText(s1, s2);
|
result:=AnsiCompareText(s1,s2)
|
||||||
|
else
|
||||||
|
result:=CompareText(s1,s2);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user