mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-15 10:51:08 +02:00
* Implemented LineBreak property for TStrings
git-svn-id: trunk@30300 -
This commit is contained in:
parent
011e8fcd07
commit
e3111faa2e
@ -609,6 +609,7 @@ type
|
|||||||
FAdapter: IStringsAdapter;
|
FAdapter: IStringsAdapter;
|
||||||
FLBS : TTextLineBreakStyle;
|
FLBS : TTextLineBreakStyle;
|
||||||
FStrictDelimiter : Boolean;
|
FStrictDelimiter : Boolean;
|
||||||
|
FLineBreak : String;
|
||||||
function GetCommaText: string;
|
function GetCommaText: string;
|
||||||
function GetName(Index: Integer): string;
|
function GetName(Index: Integer): string;
|
||||||
function GetValue(const Name: string): string;
|
function GetValue(const Name: string): string;
|
||||||
@ -626,6 +627,8 @@ type
|
|||||||
Function GetDelimiter : Char;
|
Function GetDelimiter : Char;
|
||||||
Function GetNameValueSeparator : Char;
|
Function GetNameValueSeparator : Char;
|
||||||
Function GetQuoteChar: Char;
|
Function GetQuoteChar: Char;
|
||||||
|
Function GetLineBreak : String;
|
||||||
|
procedure SetLineBreak(const S : String);
|
||||||
protected
|
protected
|
||||||
procedure DefineProperties(Filer: TFiler); override;
|
procedure DefineProperties(Filer: TFiler); override;
|
||||||
procedure Error(const Msg: string; Data: Integer);
|
procedure Error(const Msg: string; Data: Integer);
|
||||||
@ -647,6 +650,8 @@ type
|
|||||||
Function GetValueFromIndex(Index: Integer): string;
|
Function GetValueFromIndex(Index: Integer): string;
|
||||||
Procedure SetValueFromIndex(Index: Integer; const Value: string);
|
Procedure SetValueFromIndex(Index: Integer; const Value: string);
|
||||||
Procedure CheckSpecialChars;
|
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
|
public
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Add(const S: string): Integer; virtual;
|
function Add(const S: string): Integer; virtual;
|
||||||
@ -682,6 +687,7 @@ type
|
|||||||
Property TextLineBreakStyle : TTextLineBreakStyle Read GetLBS Write SetLBS;
|
Property TextLineBreakStyle : TTextLineBreakStyle Read GetLBS Write SetLBS;
|
||||||
property Delimiter: Char read GetDelimiter write SetDelimiter;
|
property Delimiter: Char read GetDelimiter write SetDelimiter;
|
||||||
property DelimitedText: string read GetDelimitedText write SetDelimitedText;
|
property DelimitedText: string read GetDelimitedText write SetDelimitedText;
|
||||||
|
property LineBreak : string Read GetLineBreak write SetLineBreak;
|
||||||
Property StrictDelimiter : Boolean Read FStrictDelimiter Write FStrictDelimiter;
|
Property StrictDelimiter : Boolean Read FStrictDelimiter Write FStrictDelimiter;
|
||||||
property QuoteChar: Char read GetQuoteChar write SetQuoteChar;
|
property QuoteChar: Char read GetQuoteChar write SetQuoteChar;
|
||||||
Property NameValueSeparator : Char Read GetNameValueSeparator Write SetNameValueSeparator;
|
Property NameValueSeparator : Char Read GetNameValueSeparator Write SetNameValueSeparator;
|
||||||
|
@ -76,6 +76,7 @@ begin
|
|||||||
FNameValueSeparator:='=';
|
FNameValueSeparator:='=';
|
||||||
FLBS:=DefaultTextLineBreakStyle;
|
FLBS:=DefaultTextLineBreakStyle;
|
||||||
FSpecialCharsInited:=true;
|
FSpecialCharsInited:=true;
|
||||||
|
FLineBreak:=sLineBreak;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -103,6 +104,18 @@ begin
|
|||||||
Result:=FDelimiter;
|
Result:=FDelimiter;
|
||||||
end;
|
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);
|
procedure TStrings.SetQuoteChar(c:Char);
|
||||||
begin
|
begin
|
||||||
@ -487,11 +500,14 @@ Var P : Pchar;
|
|||||||
begin
|
begin
|
||||||
CheckSpecialChars;
|
CheckSpecialChars;
|
||||||
// Determine needed place
|
// Determine needed place
|
||||||
Case FLBS of
|
if FLineBreak<>sLineBreak then
|
||||||
tlbsLF : NL:=#10;
|
NL:=FLineBreak
|
||||||
tlbsCRLF : NL:=#13#10;
|
else
|
||||||
tlbsCR : NL:=#13;
|
Case FLBS of
|
||||||
end;
|
tlbsLF : NL:=#10;
|
||||||
|
tlbsCRLF : NL:=#13#10;
|
||||||
|
tlbsCR : NL:=#13;
|
||||||
|
end;
|
||||||
L:=0;
|
L:=0;
|
||||||
NLS:=Length(NL);
|
NLS:=Length(NL);
|
||||||
For I:=0 to count-1 do
|
For I:=0 to count-1 do
|
||||||
@ -541,7 +557,7 @@ begin
|
|||||||
// Empty.
|
// Empty.
|
||||||
end;
|
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
|
Var
|
||||||
PS : PChar;
|
PS : PChar;
|
||||||
@ -575,6 +591,28 @@ begin
|
|||||||
Result:=True;
|
Result:=True;
|
||||||
end;
|
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);
|
Procedure TStrings.DoSetTextStr(const Value: string; DoClear : Boolean);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
@ -587,8 +625,14 @@ begin
|
|||||||
if DoClear then
|
if DoClear then
|
||||||
Clear;
|
Clear;
|
||||||
P:=1;
|
P:=1;
|
||||||
While GetNextLine (Value,S,P) do
|
if FLineBreak=sLineBreak then
|
||||||
Add(S);
|
begin
|
||||||
|
While GetNextLine (Value,S,P) do
|
||||||
|
Add(S)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
While GetNextLineBreak (Value,S,P) do
|
||||||
|
Add(S);
|
||||||
finally
|
finally
|
||||||
EndUpdate;
|
EndUpdate;
|
||||||
end;
|
end;
|
||||||
@ -597,12 +641,14 @@ end;
|
|||||||
Procedure TStrings.SetTextStr(const Value: string);
|
Procedure TStrings.SetTextStr(const Value: string);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
CheckSpecialChars;
|
||||||
DoSetTextStr(Value,True);
|
DoSetTextStr(Value,True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure TStrings.AddText(const S: string);
|
Procedure TStrings.AddText(const S: string);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
CheckSpecialChars;
|
||||||
DoSetTextStr(S,False);
|
DoSetTextStr(S,False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user