* Implemented LineBreak property for TStrings

git-svn-id: trunk@30300 -
This commit is contained in:
michael 2015-03-24 08:38:52 +00:00
parent 011e8fcd07
commit e3111faa2e
2 changed files with 60 additions and 8 deletions

View File

@ -609,6 +609,7 @@ type
FAdapter: IStringsAdapter;
FLBS : TTextLineBreakStyle;
FStrictDelimiter : Boolean;
FLineBreak : String;
function GetCommaText: string;
function GetName(Index: Integer): string;
function GetValue(const Name: string): string;
@ -626,6 +627,8 @@ type
Function GetDelimiter : Char;
Function GetNameValueSeparator : Char;
Function GetQuoteChar: Char;
Function GetLineBreak : String;
procedure SetLineBreak(const S : String);
protected
procedure DefineProperties(Filer: TFiler); override;
procedure Error(const Msg: string; Data: Integer);
@ -647,6 +650,8 @@ type
Function GetValueFromIndex(Index: Integer): string;
Procedure SetValueFromIndex(Index: Integer; const Value: string);
Procedure CheckSpecialChars;
Class Function GetNextLine (Const Value : String; Var S : String; Var P : Integer) : Boolean;
Function GetNextLinebreak (Const Value : String; Var S : String; Var P : Integer) : Boolean;
public
destructor Destroy; override;
function Add(const S: string): Integer; virtual;
@ -682,6 +687,7 @@ type
Property TextLineBreakStyle : TTextLineBreakStyle Read GetLBS Write SetLBS;
property Delimiter: Char read GetDelimiter write SetDelimiter;
property DelimitedText: string read GetDelimitedText write SetDelimitedText;
property LineBreak : string Read GetLineBreak write SetLineBreak;
Property StrictDelimiter : Boolean Read FStrictDelimiter Write FStrictDelimiter;
property QuoteChar: Char read GetQuoteChar write SetQuoteChar;
Property NameValueSeparator : Char Read GetNameValueSeparator Write SetNameValueSeparator;

View File

@ -76,6 +76,7 @@ begin
FNameValueSeparator:='=';
FLBS:=DefaultTextLineBreakStyle;
FSpecialCharsInited:=true;
FLineBreak:=sLineBreak;
end;
end;
@ -103,6 +104,18 @@ begin
Result:=FDelimiter;
end;
procedure TStrings.SetLineBreak(Const S : String);
begin
CheckSpecialChars;
FLineBreak:=S;
end;
Function TStrings.GetLineBreak : String;
begin
CheckSpecialChars;
Result:=FLineBreak;
end;
procedure TStrings.SetQuoteChar(c:Char);
begin
@ -487,11 +500,14 @@ Var P : Pchar;
begin
CheckSpecialChars;
// Determine needed place
Case FLBS of
tlbsLF : NL:=#10;
tlbsCRLF : NL:=#13#10;
tlbsCR : NL:=#13;
end;
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
@ -541,7 +557,7 @@ begin
// Empty.
end;
Function GetNextLine (Const Value : String; Var S : String; Var P : Integer) : Boolean;
Class Function TStrings.GetNextLine (Const Value : String; Var S : String; Var P : Integer) : Boolean;
Var
PS : PChar;
@ -575,6 +591,28 @@ begin
Result:=True;
end;
Function TStrings.GetNextLineBreak (Const Value : String; Var S : String; Var P : Integer) : Boolean;
Var
PS,PC,PP : PChar;
IP,L : Integer;
begin
S:='';
Result:=False;
If ((Length(Value)-P)<=0) then
exit;
PS:=@Value[P];
PC:=PS;
PP:=AnsiStrPos(PS,PChar(FLineBreak));
// Stop on #0.
While (PC^<>#0) and (PC<>PP) do
Inc(PC);
P:=P+(PC-PS)+Length(FLineBreak);
SetString(S,PS,PC-PS);
Result:=True;
end;
Procedure TStrings.DoSetTextStr(const Value: string; DoClear : Boolean);
Var
@ -587,8 +625,14 @@ begin
if DoClear then
Clear;
P:=1;
While GetNextLine (Value,S,P) do
Add(S);
if FLineBreak=sLineBreak then
begin
While GetNextLine (Value,S,P) do
Add(S)
end
else
While GetNextLineBreak (Value,S,P) do
Add(S);
finally
EndUpdate;
end;
@ -597,12 +641,14 @@ end;
Procedure TStrings.SetTextStr(const Value: string);
begin
CheckSpecialChars;
DoSetTextStr(Value,True);
end;
Procedure TStrings.AddText(const S: string);
begin
CheckSpecialChars;
DoSetTextStr(S,False);
end;