Browse Source

# revisions: 32792,32815,32816

git-svn-id: branches/fixes_3_0@33757 -
marco 9 years ago
parent
commit
4d37bd0804

+ 2 - 0
.gitattributes

@@ -6816,6 +6816,7 @@ packages/rtl-objpas/src/inc/varerror.inc svneol=native#text/plain
 packages/rtl-objpas/src/inc/variants.pp svneol=native#text/plain
 packages/rtl-objpas/src/inc/varutilh.inc svneol=native#text/plain
 packages/rtl-objpas/src/inc/varutils.inc svneol=native#text/plain
+packages/rtl-objpas/src/inc/widestrutils.pp svneol=native#text/plain
 packages/rtl-objpas/src/morphos/varutils.pp svneol=native#text/plain
 packages/rtl-objpas/src/msdos/varutils.pp svneol=native#text/plain
 packages/rtl-objpas/src/nativent/varutils.pp svneol=native#text/pascal
@@ -9026,6 +9027,7 @@ rtl/objpas/sysutils/sysint.inc svneol=native#text/plain
 rtl/objpas/sysutils/sysinth.inc svneol=native#text/plain
 rtl/objpas/sysutils/syspch.inc svneol=native#text/plain
 rtl/objpas/sysutils/syspchh.inc svneol=native#text/plain
+rtl/objpas/sysutils/syssr.inc svneol=native#text/plain
 rtl/objpas/sysutils/sysstr.inc svneol=native#text/plain
 rtl/objpas/sysutils/sysstrh.inc svneol=native#text/plain
 rtl/objpas/sysutils/systhrdh.inc svneol=native#text/plain

+ 1 - 0
packages/rtl-objpas/fpmake.pp

@@ -61,6 +61,7 @@ begin
 
 
     T:=P.Targets.AddUnit('strutils.pp',StrUtilsOses);
+    T:=P.Targets.AddUnit('widestrutils.pp',StrUtilsOses-ConvUtilOSes);
     T:=P.Targets.AddUnit('varutils.pp',VarUtilsOses);
     with T.Dependencies do
       begin

+ 56 - 0
packages/rtl-objpas/src/inc/widestrutils.pp

@@ -0,0 +1,56 @@
+unit WideStrUtils;
+
+{$mode objfpc}
+{$H+}
+{$inline on}
+
+interface
+
+uses
+  SysUtils;
+
+function WideStringReplace(const S, OldPattern, NewPattern: WideString; Flags: TReplaceFlags): WideString;
+function WideReplaceStr(const AText, AFromText, AToText: WideString): WideString; inline;
+function WideReplaceText(const AText, AFromText, AToText: WideString): WideString; inline;
+
+function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString; Flags: TReplaceFlags): UnicodeString;
+function UnicodeReplaceStr(const AText, AFromText, AToText: UnicodeString): UnicodeString; inline;
+function UnicodeReplaceText(const AText, AFromText, AToText: UnicodeString): UnicodeString; inline;
+
+
+implementation
+
+function WideReplaceStr(const AText, AFromText, AToText: WideString): WideString; inline;
+begin
+  Result := WideStringReplace(AText, AFromText, AToText, [rfReplaceAll]);
+end;
+
+function WideReplaceText(const AText, AFromText, AToText: WideString): WideString; inline;
+begin
+  Result := WideStringReplace(AText, AFromText, AToText, [rfReplaceAll, rfIgnoreCase]);
+end;
+
+function UnicodeReplaceStr(const AText, AFromText, AToText: UnicodeString): UnicodeString; inline;
+begin
+  Result := UnicodeStringReplace(AText, AFromText, AToText, [rfReplaceAll]);
+end;
+
+function UnicodeReplaceText(const AText, AFromText, AToText: UnicodeString): UnicodeString; inline;
+begin
+  Result := UnicodeStringReplace(AText, AFromText, AToText, [rfReplaceAll, rfIgnoreCase]);
+end;
+
+Function WideStringReplace(const S, OldPattern, NewPattern: WideString; Flags: TReplaceFlags): WideString;
+
+begin
+  Result:= sysutils.WideStringReplace(S,OldPattern,NewPattern,Flags);
+end;
+
+Function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString; Flags: TReplaceFlags): UnicodeString;
+
+begin
+  Result:= sysutils.UnicodeStringReplace(S,OldPattern,NewPattern,Flags);
+end;
+
+end.
+

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

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

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

@@ -80,6 +80,20 @@ begin
     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;
 begin
   CheckSpecialChars;
@@ -512,6 +526,8 @@ begin
   NLS:=Length(NL);
   For I:=0 to count-1 do
     L:=L+Length(Strings[I])+NLS;
+  if SkipLastLineBreak then
+    Dec(L,NLS);
   Setlength(Result,L);
   P:=Pointer(Result);
   For i:=0 To count-1 do
@@ -521,11 +537,12 @@ begin
     if L<>0 then
       System.Move(Pointer(S)^,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;
 

+ 36 - 0
rtl/objpas/sysutils/syssr.inc

@@ -0,0 +1,36 @@
+var
+  Srch,OldP,RemS: SRString; // Srch and Oldp can contain uppercase versions of S,OldPattern
+  P : Integer;
+begin
+  Srch:=S;
+  OldP:=OldPattern;
+  if rfIgnoreCase in Flags then
+    begin
+    Srch:=SRUpperCase(Srch);
+    OldP:=SRUpperCase(OldP);
+    end;
+  RemS:=S;
+  Result:='';
+  while (Length(Srch)<>0) do
+    begin
+    P:=AnsiPos(OldP, Srch);
+    if P=0 then
+      begin
+      Result:=Result+RemS;
+      Srch:='';
+      end
+    else
+      begin
+      Result:=Result+Copy(RemS,1,P-1)+NewPattern;
+      P:=P+Length(OldP);
+      RemS:=Copy(RemS,P,Length(RemS)-P+1);
+      if not (rfReplaceAll in Flags) then
+        begin
+        Result:=Result+RemS;
+        Srch:='';
+        end
+      else
+         Srch:=Copy(Srch,P,Length(Srch)-P+1);
+      end;
+    end;
+end;

+ 8 - 36
rtl/objpas/sysutils/sysstr.inc

@@ -2651,45 +2651,17 @@ begin
     Dec(Result);
 end;
 
+{$macro on}
+{$define INSTRINGREPLACE}
+{$define SRString:=String}
+{$define SRUpperCase:=AnsiUppercase}
 
 Function StringReplace(const S, OldPattern, NewPattern: string;  Flags: TReplaceFlags): string;
-var
-  Srch,OldP,RemS: string; // Srch and Oldp can contain uppercase versions of S,OldPattern
-  P : Integer;
-begin
-  Srch:=S;
-  OldP:=OldPattern;
-  if rfIgnoreCase in Flags then
-    begin
-    Srch:=AnsiUpperCase(Srch);
-    OldP:=AnsiUpperCase(OldP);
-    end;
-  RemS:=S;
-  Result:='';
-  while (Length(Srch)<>0) do
-    begin
-    P:=AnsiPos(OldP, Srch);
-    if P=0 then
-      begin
-      Result:=Result+RemS;
-      Srch:='';
-      end
-    else
-      begin
-      Result:=Result+Copy(RemS,1,P-1)+NewPattern;
-      P:=P+Length(OldP);
-      RemS:=Copy(RemS,P,Length(RemS)-P+1);
-      if not (rfReplaceAll in Flags) then
-        begin
-        Result:=Result+RemS;
-        Srch:='';
-        end
-      else
-         Srch:=Copy(Srch,P,Length(Srch)-P+1);
-      end;
-    end;
-end;
+{$i syssr.inc}
 
+{$undef INSTRINGREPLACE}
+{$undef SRString}
+{$undef SRUpperCase}
 
 Function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
 

+ 11 - 0
rtl/objpas/sysutils/sysuni.inc

@@ -532,3 +532,14 @@ function ByteLength(const S: UnicodeString): Integer;
 begin
   Result:=Length(S)*SizeOf(UnicodeChar);
 end;
+
+{$macro on}
+{$define INUNICODESTRINGREPLACE}
+{$define SRString:=UnicodeString}
+{$define SRUpperCase:=WideUppercase}
+function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags): UnicodeString;
+{$i syssr.inc}
+
+{$undef INUNICODESTRINGREPLACE}
+{$undef SRString}
+{$undef SRUpperCase}

+ 1 - 0
rtl/objpas/sysutils/sysunih.inc

@@ -67,3 +67,4 @@ function StringOf(const Bytes: TBytes): UnicodeString;
 function WideBytesOf(const Value: UnicodeString): TBytes;
 function WideStringOf(const Value: TBytes): UnicodeString;
 function ByteLength(const S: UnicodeString): Integer;
+function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString;  Flags: TReplaceFlags): UnicodeString;

+ 11 - 0
rtl/objpas/sysutils/syswide.inc

@@ -179,3 +179,14 @@ Function CharInSet(Ch:WideChar;Const CSet : TSysCharSet) : Boolean;
 begin
   result:=(Ch<=#$FF) and (ansichar(byte(ch)) in CSet);
 end;
+
+{$macro on}
+{$define INWIDESTRINGREPLACE}
+{$define SRString:=WideString}
+{$define SRUpperCase:=WideUppercase}
+function WideStringReplace(const S, OldPattern, NewPattern: WideString;  Flags: TReplaceFlags): WideString;
+{$i syssr.inc}
+
+{$undef INWIDESTRINGREPLACE}
+{$undef SRString}
+{$undef SRUpperCase}

+ 1 - 0
rtl/objpas/sysutils/syswideh.inc

@@ -34,3 +34,4 @@ function StrLen(p: pwidechar): sizeint; external name 'FPC_PWIDECHAR_LENGTH'; ov
 function StrCopy(Dest, Source: PWideChar): PWideChar; overload;
 function StrLCopy(Dest,Source: PWideChar; MaxLen: SizeInt): PWideChar; overload;
 Function CharInSet(Ch:WideChar;Const CSet : TSysCharSet) : Boolean;
+function WideStringReplace(const S, OldPattern, NewPattern: WideString;  Flags: TReplaceFlags): WideString;