Procházet zdrojové kódy

* Fix bug ID #31975, LastIndexOf string helper copy&paste error

git-svn-id: trunk@36703 -
michael před 8 roky
rodič
revize
f247a66c90
1 změnil soubory, kde provedl 27 přidání a 3 odebrání
  1. 27 3
      rtl/objpas/sysutils/syshelp.inc

+ 27 - 3
rtl/objpas/sysutils/syshelp.inc

@@ -937,10 +937,34 @@ begin
 end;
 end;
 
 
 
 
-function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: Integer;
-  ACount: Integer): Integer;
+function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: Integer; ACount: Integer): Integer;
+  
+var
+  I,L,LS,M : Integer;
+  S : String;
+  P : PChar;
+    
 begin
 begin
-  Result:=LastIndexOf(AValue,AStartIndex,AStartIndex+1);
+  Result:=-1;
+  LS:=system.Length(Self);
+  L:=system.Length(AValue);
+  if (L=0) or (L>LS) then
+    Exit;
+  P:=PChar(AValue);  
+  S:=Self;
+  I:=AStartIndex+1; // 1 based
+  if (I>LS) then
+    I:=LS;
+  I:=I-L+1;
+  M:=AStartIndex-ACount+1; // 1 based
+  if M<1 then
+    M:=1;
+  while (Result=-1) and (I>=M) do
+    begin
+    if (0=StrLComp(PChar(@S[I]),P,L)) then
+      Result:=I-1;
+    Dec(I);
+    end;
 end;
 end;