View Issue Details

IDProjectCategoryView StatusLast Update
0035047FPCRTLpublic2019-05-27 17:23
Reporterrd0xAssigned ToMarco van de Voort 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.2.0Product Build 
Target VersionFixed in Version3.3.1 
Summary0035047: Missing ContainsText function from Delphi
DescriptionAdd ContainsText for Delphi compatibility

http://docwiki.embarcadero.com/Libraries/Rio/en/System.StrUtils.ContainsText
TagsNo tags attached.
Fixed in Revision41263
FPCOldBugId
FPCTarget
Attached Files
  • StrUtils.diff (4,326 bytes)
    Index: packages/rtl-objpas/src/inc/strutils.pp
    ===================================================================
    --- packages/rtl-objpas/src/inc/strutils.pp	(revision 41259)
    +++ packages/rtl-objpas/src/inc/strutils.pp	(working copy)
    @@ -20,7 +20,7 @@
     interface
     
     uses
    -  SysUtils{, Types};
    +  SysUtils, Types;
     
     { ---------------------------------------------------------------------
         Case insensitive search/replace
    @@ -36,6 +36,11 @@
     Function StartsText(const ASubText, AText: string): Boolean; inline;
     Function EndsText(const ASubText, AText: string): Boolean; inline;
     
    +function ResemblesText(const AText, AOther: string): Boolean; inline;
    +function ContainsText(const AText, ASubText: string): Boolean; inline;
    +function MatchText(const AText: string; const AValues: array of string): Boolean; inline;
    +function IndexText(const AText: string; const AValues: array of string): Integer; inline;
    +
     { ---------------------------------------------------------------------
         Case sensitive search/replace
       ---------------------------------------------------------------------}
    @@ -54,6 +59,11 @@
     Function IndexText(const AText: UnicodeString; const AValues: array of UnicodeString): Integer;
     Operator in (const AText: string; const AValues: array of string):Boolean;inline;
     Operator in (const AText: UnicodeString; const AValues: array of UnicodeString):Boolean;inline;
    +
    +function ContainsStr(const AText, ASubText: string): Boolean; inline;
    +function MatchStr(const AText: string; const AValues: array of string): Boolean; inline;
    +function IndexStr(const AText: string; const AValues: array of string): Integer; inline;
    +
     { ---------------------------------------------------------------------
         Miscellaneous
       ---------------------------------------------------------------------}
    @@ -67,6 +77,8 @@
     function NaturalCompareText (const S1 , S2 : string ): Integer ;
     function NaturalCompareText(const Str1, Str2: string; const ADecSeparator, AThousandSeparator: Char): Integer;
     
    +function SplitString(const S, Delimiters: string): TStringDynArray;
    +
     { ---------------------------------------------------------------------
         VB emulations.
       ---------------------------------------------------------------------}
    @@ -146,6 +158,7 @@
     
     Const
       AnsiResemblesProc: TCompareTextProc = @SoundexProc;
    +  ResemblesProc: TCompareTextProc = @SoundexProc;
     
     { ---------------------------------------------------------------------
         Other functions, based on RxStrUtils.
    @@ -927,19 +940,54 @@
       Result := AnsiEndsText(ASubText, AText);
     end;
     
    +function ResemblesText(const AText, AOther: string): Boolean;
    +begin
    +  if Assigned(ResemblesProc) then
    +    Result := ResemblesProc(AText, AOther)
    +  else
    +    Result := False;
    +end;
     
    +function ContainsText(const AText, ASubText: string): Boolean;
    +begin
    +  Result := AnsiContainsText(AText, ASubText);
    +end;
    +
    +function MatchText(const AText: string; const AValues: array of string): Boolean;
    +begin
    +  Result := AnsiMatchText(AText, AValues);
    +end;
    +
    +function IndexText(const AText: string; const AValues: array of string): Integer;
    +begin
    +  Result := AnsiIndexText(AText, AValues);
    +end;
    +
    +function ContainsStr(const AText, ASubText: string): Boolean;
    +begin
    +  Result := AnsiContainsStr(AText, ASubText);
    +end;
    +
    +function MatchStr(const AText: string; const AValues: array of string): Boolean;
    +begin
    +  Result := AnsiMatchStr(AText, AValues);
    +end;
    +
    +function IndexStr(const AText: string; const AValues: array of string): Integer;
    +begin
    +  Result := AnsiIndexStr(AText, AValues);
    +end;
    +
     function AnsiReplaceText(const AText, AFromText, AToText: string): string;
     begin
       Result := StringReplace(AText,AFromText,AToText,[rfReplaceAll,rfIgnoreCase]);
     end;
     
    -
     function AnsiMatchText(const AText: string; const AValues: array of string): Boolean;
     begin
       Result:=(AnsiIndexText(AText,AValues)<>-1)
     end;
     
    -
     function AnsiIndexText(const AText: string; const AValues: array of string): Integer;
     begin
       for Result := Low(AValues) to High(AValues) do
    @@ -1292,6 +1340,11 @@
       end;
     end;
     
    +function SplitString(const S, Delimiters: string): TStringDynArray;
    +begin
    +  Result := S.Split(Delimiters);
    +end;
    +
     function NaturalCompareText (const S1 , S2 : string ): Integer ;
     begin
       Result := NaturalCompareText(S1, S2,
    
    StrUtils.diff (4,326 bytes)

Activities

Thaddy de Koning

2019-02-09 11:10

reporter   ~0113970

The string helpers in sysutils have this functionality.

Ugochukwu Mmaduekwe

2019-02-09 11:58

reporter   ~0113972

@thaddy, while this is true, some of us avoid the string helpers in SysUtils for specific purposes one of which is that they are unfortunately zerobased like in Delphi.

Serge Anvarov

2019-02-09 12:29

reporter   ~0113974

Add patch

Serge Anvarov

2019-02-09 12:30

reporter  

StrUtils.diff (4,326 bytes)
Index: packages/rtl-objpas/src/inc/strutils.pp
===================================================================
--- packages/rtl-objpas/src/inc/strutils.pp	(revision 41259)
+++ packages/rtl-objpas/src/inc/strutils.pp	(working copy)
@@ -20,7 +20,7 @@
 interface
 
 uses
-  SysUtils{, Types};
+  SysUtils, Types;
 
 { ---------------------------------------------------------------------
     Case insensitive search/replace
@@ -36,6 +36,11 @@
 Function StartsText(const ASubText, AText: string): Boolean; inline;
 Function EndsText(const ASubText, AText: string): Boolean; inline;
 
+function ResemblesText(const AText, AOther: string): Boolean; inline;
+function ContainsText(const AText, ASubText: string): Boolean; inline;
+function MatchText(const AText: string; const AValues: array of string): Boolean; inline;
+function IndexText(const AText: string; const AValues: array of string): Integer; inline;
+
 { ---------------------------------------------------------------------
     Case sensitive search/replace
   ---------------------------------------------------------------------}
@@ -54,6 +59,11 @@
 Function IndexText(const AText: UnicodeString; const AValues: array of UnicodeString): Integer;
 Operator in (const AText: string; const AValues: array of string):Boolean;inline;
 Operator in (const AText: UnicodeString; const AValues: array of UnicodeString):Boolean;inline;
+
+function ContainsStr(const AText, ASubText: string): Boolean; inline;
+function MatchStr(const AText: string; const AValues: array of string): Boolean; inline;
+function IndexStr(const AText: string; const AValues: array of string): Integer; inline;
+
 { ---------------------------------------------------------------------
     Miscellaneous
   ---------------------------------------------------------------------}
@@ -67,6 +77,8 @@
 function NaturalCompareText (const S1 , S2 : string ): Integer ;
 function NaturalCompareText(const Str1, Str2: string; const ADecSeparator, AThousandSeparator: Char): Integer;
 
+function SplitString(const S, Delimiters: string): TStringDynArray;
+
 { ---------------------------------------------------------------------
     VB emulations.
   ---------------------------------------------------------------------}
@@ -146,6 +158,7 @@
 
 Const
   AnsiResemblesProc: TCompareTextProc = @SoundexProc;
+  ResemblesProc: TCompareTextProc = @SoundexProc;
 
 { ---------------------------------------------------------------------
     Other functions, based on RxStrUtils.
@@ -927,19 +940,54 @@
   Result := AnsiEndsText(ASubText, AText);
 end;
 
+function ResemblesText(const AText, AOther: string): Boolean;
+begin
+  if Assigned(ResemblesProc) then
+    Result := ResemblesProc(AText, AOther)
+  else
+    Result := False;
+end;
 
+function ContainsText(const AText, ASubText: string): Boolean;
+begin
+  Result := AnsiContainsText(AText, ASubText);
+end;
+
+function MatchText(const AText: string; const AValues: array of string): Boolean;
+begin
+  Result := AnsiMatchText(AText, AValues);
+end;
+
+function IndexText(const AText: string; const AValues: array of string): Integer;
+begin
+  Result := AnsiIndexText(AText, AValues);
+end;
+
+function ContainsStr(const AText, ASubText: string): Boolean;
+begin
+  Result := AnsiContainsStr(AText, ASubText);
+end;
+
+function MatchStr(const AText: string; const AValues: array of string): Boolean;
+begin
+  Result := AnsiMatchStr(AText, AValues);
+end;
+
+function IndexStr(const AText: string; const AValues: array of string): Integer;
+begin
+  Result := AnsiIndexStr(AText, AValues);
+end;
+
 function AnsiReplaceText(const AText, AFromText, AToText: string): string;
 begin
   Result := StringReplace(AText,AFromText,AToText,[rfReplaceAll,rfIgnoreCase]);
 end;
 
-
 function AnsiMatchText(const AText: string; const AValues: array of string): Boolean;
 begin
   Result:=(AnsiIndexText(AText,AValues)<>-1)
 end;
 
-
 function AnsiIndexText(const AText: string; const AValues: array of string): Integer;
 begin
   for Result := Low(AValues) to High(AValues) do
@@ -1292,6 +1340,11 @@
   end;
 end;
 
+function SplitString(const S, Delimiters: string): TStringDynArray;
+begin
+  Result := S.Split(Delimiters);
+end;
+
 function NaturalCompareText (const S1 , S2 : string ): Integer ;
 begin
   Result := NaturalCompareText(S1, S2,
StrUtils.diff (4,326 bytes)

Marco van de Voort

2019-02-09 13:31

manager   ~0113978

Committed patch, thanks!

rd0x

2019-02-09 14:30

reporter   ~0113979

The patch is not unicode aware, or?

rd0x

2019-02-09 14:35

reporter   ~0113980

Last edited: 2019-02-09 15:02

View 4 revisions

Might be better to use added code from earlier reports: 0033078, 0033079
Which are added again now -> duplicates?

Marco van de Voort

2019-02-09 15:16

manager   ~0113984

Last edited: 2019-02-09 15:17

View 2 revisions

No unicodestring vs normal string.

The normal strings work fine with utf8 in default lazarus mode. That's why the compiler didn't balk at it.

Marco van de Voort

2019-02-11 13:41

manager   ~0114031

No response, close again

Issue History

Date Modified Username Field Change
2019-02-09 11:03 rd0x New Issue
2019-02-09 11:10 Thaddy de Koning Note Added: 0113970
2019-02-09 11:58 Ugochukwu Mmaduekwe Note Added: 0113972
2019-02-09 12:29 Serge Anvarov Note Added: 0113974
2019-02-09 12:30 Serge Anvarov File Added: StrUtils.diff
2019-02-09 13:31 Marco van de Voort Fixed in Revision => 41263
2019-02-09 13:31 Marco van de Voort Note Added: 0113978
2019-02-09 13:31 Marco van de Voort Status new => resolved
2019-02-09 13:31 Marco van de Voort Fixed in Version => 3.3.1
2019-02-09 13:31 Marco van de Voort Resolution open => fixed
2019-02-09 13:31 Marco van de Voort Assigned To => Marco van de Voort
2019-02-09 14:30 rd0x Note Added: 0113979
2019-02-09 14:30 rd0x Status resolved => feedback
2019-02-09 14:30 rd0x Resolution fixed => reopened
2019-02-09 14:35 rd0x Note Added: 0113980
2019-02-09 14:35 rd0x Status feedback => assigned
2019-02-09 14:36 rd0x Note Edited: 0113980 View Revisions
2019-02-09 15:02 Marco van de Voort Note Edited: 0113980 View Revisions
2019-02-09 15:02 Marco van de Voort Note Edited: 0113980 View Revisions
2019-02-09 15:16 Marco van de Voort Note Added: 0113984
2019-02-09 15:17 Marco van de Voort Note Edited: 0113984 View Revisions
2019-02-11 13:41 Marco van de Voort Note Added: 0114031
2019-02-11 13:41 Marco van de Voort Status assigned => resolved
2019-02-11 13:41 Marco van de Voort Resolution reopened => fixed
2019-05-27 17:23 rd0x Status resolved => closed