Browse Source

* Fix bug #27831

git-svn-id: trunk@30642 -
michael 10 years ago
parent
commit
27b1fb0439
1 changed files with 43 additions and 36 deletions
  1. 43 36
      packages/rtl-objpas/src/inc/strutils.pp

+ 43 - 36
packages/rtl-objpas/src/inc/strutils.pp

@@ -1770,39 +1770,10 @@ begin
     end;
     end;
 end;
 end;
 
 
-function isWild(inputStr, Wilds: string; ignoreCase: boolean): boolean;
+Function isMatch(inputstr,wilds : string; CWild, CinputWord: integer;MaxInputword,maxwilds : word) : Boolean;
 
 
-var
-  CWild, CinputWord: integer; { counter for positions }
-  i: integer;
-  MaxinputWord, MaxWilds: integer; { Length of inputStr and Wilds }
 begin
 begin
-  Result:=true;
-  if Wilds = inputStr then
-    Exit;
-  { delete '**', because '**' = '*' }
-  i:=Pos('**', Wilds);
-  while i > 0 do
-    begin
-    Delete(Wilds, i, 1);
-    i:=Pos('**', Wilds);
-    end;
-  if Wilds = '*' then { for fast end, if Wilds only '*' }
-    Exit;
-  MaxinputWord:=Length(inputStr);
-  MaxWilds:=Length(Wilds);
-  if (MaxWilds = 0) or (MaxinputWord = 0) then
-    begin
-    Result:=false;
-    Exit;
-    end;
-  if ignoreCase then { upcase all letters }
-    begin
-    inputStr:=AnsiUpperCase(inputStr);
-    Wilds:=AnsiUpperCase(Wilds);
-    end;
-  CinputWord:=1;
-  CWild:=1;
+  Result:=True;
   repeat
   repeat
     if Wilds[CWild] = '*' then { handling of '*' }
     if Wilds[CWild] = '*' then { handling of '*' }
       begin
       begin
@@ -1814,9 +1785,13 @@ begin
         inc(CinputWord);
         inc(CinputWord);
         end;
         end;
       { increase until a match }
       { increase until a match }
-      while (inputStr[CinputWord] <> Wilds[CWild]) and 
-        (CinputWord <= MaxinputWord) do
-        inc(CinputWord);
+      Repeat
+        while (inputStr[CinputWord]<>Wilds[CWild]) and (CinputWord <= MaxinputWord) do
+          inc(CinputWord);
+        Result:=isMatch(inputstr,wilds,CWild, CinputWord,MaxInputword,maxwilds);
+        if not Result then
+          Inc(cInputWord);
+      Until Result or (CinputWord>=MaxinputWord);
       Continue;
       Continue;
       end;
       end;
     if Wilds[CWild] = '?' then { equal to '?' }
     if Wilds[CWild] = '?' then { equal to '?' }
@@ -1837,9 +1812,41 @@ begin
     Exit;
     Exit;
   until (CinputWord > MaxinputWord) or (CWild > MaxWilds);
   until (CinputWord > MaxinputWord) or (CWild > MaxWilds);
   { no completed evaluation }
   { no completed evaluation }
-  if (CinputWord <= MaxinputWord) or 
-     (CWild <= MaxWilds) then
+  if (CinputWord <= MaxinputWord) or (CWild <= MaxWilds) then
+    Result:=false;
+end;
+
+function isWild(inputStr, Wilds: string; ignoreCase: boolean): boolean;
+
+var
+  i: integer;
+  MaxinputWord, MaxWilds: integer; { Length of inputStr and Wilds }
+begin
+  Result:=true;
+  if Wilds = inputStr then
+    Exit;
+  { delete '**', because '**' = '*' }
+  i:=Pos('**', Wilds);
+  while i > 0 do
+    begin
+    Delete(Wilds, i, 1);
+    i:=Pos('**', Wilds);
+    end;
+  if Wilds = '*' then { for fast end, if Wilds only '*' }
+    Exit;
+  MaxinputWord:=Length(inputStr);
+  MaxWilds:=Length(Wilds);
+  if (MaxWilds = 0) or (MaxinputWord = 0) then
+    begin
     Result:=false;
     Result:=false;
+    Exit;
+    end;
+  if ignoreCase then { upcase all letters }
+    begin
+    inputStr:=AnsiUpperCase(inputStr);
+    Wilds:=AnsiUpperCase(Wilds);
+    end;
+  Result:=isMatch(inputStr,wilds,1,1,MaxinputWord, MaxWilds);  
 end;
 end;