Advertisement
Janilabo

Untitled

Dec 3rd, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.82 KB | None | 0 0
  1. function StrMatches(Expr, Str: string; Ignore: Char; Sensitive: Boolean; var Match: String): Boolean;
  2. var
  3.   TSA: TStrArray;
  4.   Hi, i, _Right, P, Left, r: Integer;
  5. begin
  6.   Result := False;
  7.   _Right := Length(Expr);
  8.   if ((_Right > 0) and not (_Right > Length(Str))) then
  9.   begin
  10.     TSA := Explode(ignore, expr);
  11.     Hi := High(TSA);
  12.     r := 0;
  13.     for i := 0 to Hi do
  14.       if (Length(TSA[i]) > 0) then
  15.       begin
  16.         TSA[r] := TSA[i];
  17.         r := (r + 1);
  18.       end;
  19.     Hi := High(TSA);
  20.     if (Hi > -1) then              
  21.     case (Hi = 0) of
  22.       False:
  23.       begin
  24.         Left := Pos(TSA[0], Str);
  25.         _Right := (Left + Length(TSA[0]));
  26.         if ((Hi > 0) and (Left > 0)) then
  27.         begin
  28.           case Sensitive of
  29.             True:
  30.               for i := 1 to Hi do
  31.               begin
  32.                 p := PosEx(TSA[i], Str, _Right);
  33.                 if (p > 0) then
  34.                   _Right := (P + Length(TSA[i]))
  35.                 else
  36.                   Exit;
  37.               end;
  38.             False:
  39.               for i := 1 to Hi do
  40.               begin
  41.                 p := LastPos(TSA[i], str);
  42.                 if (p > _Right) then
  43.                   _Right := (P + Length(TSA[i]))
  44.                 else
  45.                   Exit;
  46.               end;  
  47.           end;  
  48.           Match := Copy(Str, Left, (_Right - Left));
  49.           Result := True;      
  50.         end;          
  51.       end;    
  52.       True:
  53.       begin        
  54.         P := Pos(TSA[0], Str);
  55.         Result := (P > 0);
  56.         if Result then
  57.           match := Copy(Str, P, Length(TSA[0]));
  58.       end;
  59.     end;
  60.   end;
  61. end;
  62.  
  63. var
  64.   str, expression, match: string;
  65.  
  66. begin
  67.   expression := 'Test';
  68.   str := 'This is Test, it works!';
  69.   if StrMatches(expression, str, '*', True, match) then
  70.     WriteLn(match);
  71. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement