浏览代码

* Added SkipLastLineBreak to TStrings (bug ID 28213)

git-svn-id: trunk@32792 -
michael 9 年之前
父节点
当前提交
4f82d103af
共有 2 个文件被更改,包括 26 次插入5 次删除
  1. 4 0
      rtl/objpas/classes/classesh.inc
  2. 22 5
      rtl/objpas/classes/stringl.inc

+ 4 - 0
rtl/objpas/classes/classesh.inc

@@ -609,6 +609,7 @@ type
     FUpdateCount: Integer;
     FUpdateCount: Integer;
     FAdapter: IStringsAdapter;
     FAdapter: IStringsAdapter;
     FLBS : TTextLineBreakStyle;
     FLBS : TTextLineBreakStyle;
+    FSkipLastLineBreak : Boolean;
     FStrictDelimiter : Boolean;
     FStrictDelimiter : Boolean;
     FLineBreak : String;
     FLineBreak : String;
     function GetCommaText: string;
     function GetCommaText: string;
@@ -630,6 +631,8 @@ type
     Function GetQuoteChar: Char;
     Function GetQuoteChar: Char;
     Function GetLineBreak : String;
     Function GetLineBreak : String;
     procedure SetLineBreak(const S : String);
     procedure SetLineBreak(const S : String);
+    Function GetSkipLastLineBreak : Boolean;
+    procedure SetSkipLastLineBreak(const AValue : Boolean);
   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);
@@ -704,6 +707,7 @@ type
     property Strings[Index: Integer]: string read Get write Put; default;
     property Strings[Index: Integer]: string read Get write Put; default;
     property Text: string read GetTextStr write SetTextStr;
     property Text: string read GetTextStr write SetTextStr;
     property StringsAdapter: IStringsAdapter read FAdapter write SetStringsAdapter;
     property StringsAdapter: IStringsAdapter read FAdapter write SetStringsAdapter;
+    Property SkipLastLineBreak : Boolean Read GetSkipLastLineBreak Write SetSkipLastLineBreak;
   end;
   end;
 
 
 { TStringList class }
 { TStringList class }

+ 22 - 5
rtl/objpas/classes/stringl.inc

@@ -80,6 +80,20 @@ begin
     end;
     end;
 end;
 end;
 
 
+Function TStrings.GetSkipLastLineBreak : Boolean;
+
+begin
+  CheckSpecialChars;
+  Result:=FSkipLastLineBreak;
+end;
+
+procedure TStrings.SetSkipLastLineBreak(const AValue : Boolean);
+
+begin
+  CheckSpecialChars;
+  FSkipLastLineBreak:=AValue;
+end;
+
 Function TStrings.GetLBS : TTextLineBreakStyle;
 Function TStrings.GetLBS : TTextLineBreakStyle;
 begin
 begin
   CheckSpecialChars;
   CheckSpecialChars;
@@ -512,6 +526,8 @@ 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 SkipLastLineBreak then
+    Dec(L,NLS);
   Setlength(Result,L);
   Setlength(Result,L);
   P:=Pointer(Result);
   P:=Pointer(Result);
   For i:=0 To count-1 do
   For i:=0 To count-1 do
@@ -521,11 +537,12 @@ 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;
-    For L:=1 to NLS do
-      begin
-      P^:=NL[L];
-      inc(P);
-      end;
+    if (I<Count-1) or Not SkipLastLineBreak then
+      For L:=1 to NLS do
+        begin
+        P^:=NL[L];
+        inc(P);
+        end;
     end;
     end;
 end;
 end;