Wildcard Lookup function under Delphi
Function islike (Ax, abc:string): Boolean; Ax is a substring and ABC is a source string
Var
Abcstart, Axstart, Abclength, Axlength:integer;
ENDPARTABC, Endpartax, subax:string;
Temp, abcwww, Axwww:integer;
Begin//AAA
Temp: = 0;
Abcstart: = 1;
Axstart: = 1;
Axwww: = 1;
Abcwww: = 1;
Ax:=lowercase (AX);
Abc:=lowercase (ABC);
Abclength: = Length (ABC);
Axlength: = Length (AX);
Result: = True;
While Axstart <= Axlength does Begin//bbb
If Ax[axstart] = '? ' Then Begin
Inc (Axstart);
Inc (Abcstart);
If abcstart > Abclength+1 Then Begin
Result: = false;
break;
End;
Continue;
End;
If Ax[axstart] = ' * ' Then Begin
Inc (Axstart);
Temp: = 1;
Axwww: = Axstart;
Abcwww: = Abcstart;
Continue;
End;
If not (Ax[axstart] in ['? ', ' * ']) Then Begin//CCC
Endpartax: = Copy (ax, Axstart, Axlength-axstart + 1) + '? * ';
If pos ('? ', Endpartax) < POS (' * ', endpartax) Then Begin
Subax: = Copy (Endpartax, 1, Pos ('? ', Endpartax)-1);
Axstart: = Axstart + Pos ('? ', Endpartax)-1;
End
Else Begin
Subax: = Copy (Endpartax, 1, Pos (' * ', Endpartax)-1);
Axstart: = Axstart + Pos (' * ', endpartax)-1;
End;
ENDPARTABC: = Copy (ABC, Abcstart, Abclength-abcstart + 1);
If (POS (Subax, ENDPARTABC) <> 0) and (temp = 1)) Or (POS (Subax, ENDPARTABC) = 1) and (temp = 0) Then Begin//ddd
If temp = 1 Then Temp: = 0;
Abcstart: = Abcstart + (Pos (Subax, ENDPARTABC) + Length (Subax)-1);
End
Else Begin//ddd
If temp = 0 Then Begin
Axstart: = axwww;
Abcwww: = abcwww + 1;
Abcstart: = abcwww;
Temp: = 1;
Continue;
End;
Result: = false;
break;
End; Ddd
End; Ccc
End; Bbb
End; Aaa