Bläddra i källkod

Implemented missing StringReplace function

michael 24 år sedan
förälder
incheckning
6ad27e8960
2 ändrade filer med 53 tillägg och 2 borttagningar
  1. 47 1
      rtl/objpas/sysstr.inc
  2. 6 1
      rtl/objpas/sysstrh.inc

+ 47 - 1
rtl/objpas/sysstr.inc

@@ -1174,6 +1174,47 @@ begin
     Dec(Result);
 end;
 
+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:=UpperCase(Srch);
+    OldP:=UpperCase(OldP);
+    end;
+  RemS:=S;
+  Result:='';
+  while (Length(Srch)<>0) do
+    begin
+    P:=Pos(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;
+
+
 {
    Case Translation Tables
    Can be used in internationalization support.
@@ -1185,6 +1226,8 @@ end;
    of the OS corresponds to the one you make changes to
 }
 
+
+
 const
    { upper case translation table for character set 850 }
    CP850UCT: array[128..255] of char =
@@ -1232,7 +1275,10 @@ const
 
 {
   $Log$
-  Revision 1.1.2.8  2001-08-14 20:06:23  carl
+  Revision 1.1.2.9  2001-09-20 14:35:34  michael
+   Implemented missing StringReplace function
+
+  Revision 1.1.2.8  2001/08/14 20:06:23  carl
   -* replace ifdef linux -> ifdef unix
 
   Revision 1.1.2.7  2001/08/01 21:45:22  peter

+ 6 - 1
rtl/objpas/sysstrh.inc

@@ -30,6 +30,7 @@ type
 
    { For FloatToText }
    TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
+   TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
 
 
 function NewStr(const S: string): PString;
@@ -84,6 +85,7 @@ Function FloatToStr(Value: Extended): String;
 Function StrToFloat(Value : String) : Extended;
 Function FloatToText(Buffer: PChar; Value: Extended; format: TFloatFormat; Precision, Digits: Integer): Longint;
 function LastDelimiter(const Delimiters, S: string): Integer;
+function StringReplace(const S, OldPattern, NewPattern: string;  Flags: TReplaceFlags): string;
 
 {==============================================================================}
 {   extra functions                                                            }
@@ -95,7 +97,10 @@ function BCDToInt(Value: integer): integer;
 
 {
   $Log$
-  Revision 1.1.2.2  2000-12-07 21:48:58  michael
+  Revision 1.1.2.3  2001-09-20 14:35:34  michael
+   Implemented missing StringReplace function
+
+  Revision 1.1.2.2  2000/12/07 21:48:58  michael
   + Added LastDelimiter function
 
   Revision 1.1.2.1  2000/08/09 19:31:03  peter