瀏覽代碼

Use the MemPos approach in IsWordPresent.

Rika Ichinose 1 周之前
父節點
當前提交
afc676511f
共有 1 個文件被更改,包括 6 次插入4 次删除
  1. 6 4
      packages/rtl-objpas/src/inc/strutils.pp

+ 6 - 4
packages/rtl-objpas/src/inc/strutils.pp

@@ -2306,20 +2306,22 @@ function IsWordPresent(const W, S: string; const WordDelims: TSysCharSet): Boole
 
 var
   P,PE : PChar;
-  Wn,Sn,Wi : SizeInt;
-  Wstartc : Char;
+  Wn,Sn,Wi,Wic : SizeInt;
 
 begin
   Wn:=Length(W);
   Sn:=Length(S);
   if (Sn=0) or (Wn=0) or (Wn>Sn) then
     exit(false);
-  Wstartc:=W[1];
   P:=PChar(pointer(S))-1; { Loop starts with an extra increment. }
   PE:=P+2+Sn-Wn;
+  Wic:=0;
   repeat
+    if Wic=0 then
+      Wic:=Wn;
+    dec(Wic);
     P:=P+1;
-    Wi:=IndexCharType(P,SizeUint(Pointer(PE)-Pointer(P)) div SizeOf(Char),Wstartc);
+    Wi:=IndexCharType(P+Wic,SizeUint(Pointer(PE)-Pointer(P)) div SizeOf(Char),PChar(Pointer(W))[Wic]);
     P:=P+Wi;
   until (Wi<0) or ((P=PChar(Pointer(S))) or (P[-1] in WordDelims)) and ((P+1=PE) or (P[Wn] in WordDelims)) and (CompareByte(P^,Pointer(W)^,Wn*SizeOf(Char))=0);
   result:=Wi>=0;