TStringHelper.Starts/EndsWith
Original Reporter info from Mantis: BeniBela @benibela
-
Reporter name: Benito van der Zander
Original Reporter info from Mantis: BeniBela @benibela
- Reporter name: Benito van der Zander
Description:
the string helper looks quite useful, but let's take a close look
1297 function TStringHelper.StartsWith(const AValue: string; IgnoreCase: Boolean
1298 ): Boolean;
1299 Var
1300 L : Integer;
1301 begin
1302 L:=System.Length(AValue);
length returns sizeint nowadays, not integer. But the string helper has integer everywhere. That is not going to work with longer strings...
1303 Result:=L>0;
1304 if Result then
So no string starts with an empty string? Would it not make more sense if every string starts with an empty string?
1305 if IgnoreCase then
1306 Result:=StrLiComp(PChar(AValue),PChar(Self),L)=0
1307 else
1308 Result:=StrLComp(PChar(AValue),PChar(Self),L)=0
This stops the comparison on #0 chars.
Is that behavior supposed to be Delphi compatible or is the function just completely broken?
On the other hand endsWith handles #0, but makes an unnecessary copy
567 S:=system.Copy(Self,Length-L+1,L);
568 Result:=system.Length(S)=L;
569 if Result then
570 if IgnoreCase then
571 Result:=CompareText(S,AValue)=0
572 else
573 Result:=S=AValue;
Mantis conversion info:
- Mantis ID: 33559
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 38769 (#e4ef17b5)
- Target version: 3.2.0