DECLARE FUNCTION Like(ParseString AS STRING, Pattern AS STRING) AS INTEGER
DECLARE FUNCTION IsDigit(S AS STRING) AS INTEGER
CONST INVERT = "!"
FUNCTION IsDigit(S AS STRING) AS INTEGER
IF S >= "0" AND S <= "9" THEN
IsDigit = 1
ELSE
IsDigit = 0
END IF
END FUNCTION
FUNCTION Like(ParseString AS STRING, Pattern AS STRING) AS INTEGER
DIM prev AS INTEGER, matched AS INTEGER, reverse AS INTEGER
WHILE Pattern <> ""
SELECT CASE MID$(Pattern, 1, 1)
CASE "?"
IF ParseString = "" THEN
Like = 0
EXIT FUNCTION
END IF
CASE "#"
IF IsDigit(MID$(ParseString, 1, 1)) = 0 THEN
Like = 0
EXIT FUNCTION
END IF
CASE "*"
DO
Pattern = MID$(Pattern, 2, LEN(Pattern)-1)
LOOP UNTIL MID$(Pattern, 1, 1) <> "*"
IF Pattern = "" THEN
Like = 1
EXIT FUNCTION
END IF
WHILE ParseString <> ""
IF Like(ParseString, Pattern) THEN
Like = 1
EXIT FUNCTION
END IF
IF ParseString <> "" THEN
ParseString = MID$(ParseString, 2, LEN(ParseString)-1)
END IF
WEND
Like = 0
EXIT FUNCTION
CASE "["
reverse = (MID$(Pattern, 2, 1) = INVERT)
IF reverse THEN
Pattern = MID$(Pattern, 2, LEN(Pattern)-1)
END IF
prev = 256: matched = 0
DO
Pattern = MID$(Pattern, 2, LEN(Pattern)-1)
IF (Pattern <> "") AND (esc <> 0 OR MID$(Pattern, 1, 1) <> "]") THEN
IF MID$(Pattern, 1, 1) = "-" THEN
Pattern = MID$(Pattern, 2, LEN(Pattern)-1)
IF Pattern = "" THEN
Like = 0
EXIT FUNCTION
END IF
matched = matched OR (MID$(ParseString, 1, 1) <= MID$(Pattern, 1, 1) AND ASC(MID$(ParseString, 1, 1)) >= prev)
ELSE
matched = matched OR (MID$(ParseString, 1, 1) = MID$(Pattern, 1, 1))
END IF
prev = ASC(MID$(Pattern, 1, 1))
ELSE
EXIT DO
END IF
esc = 0
LOOP
IF (prev = 256 OR MID$(Pattern, 1, 1) <> "]" OR ABS(matched) = ABS(reverse)) THEN
Like = 0
EXIT FUNCTION
END IF
CASE ELSE
IF MID$(ParseString, 1, 1) <> MID$(Pattern, 1, 1) THEN
Like = 0
EXIT FUNCTION
END IF
END SELECT
ParseString = MID$(ParseString, 2, LEN(ParseString)-1)
Pattern = MID$(Pattern, 2, LEN(Pattern)-1)
WEND
Like = ABS(LEN(ParseString) = 0)
END FUNCTION
?Like("24","##")
?Like("aBBBa","a*a")
?Like("F","[!A-Z]")
?Like("a2a","a#a")
?Like("aM5b","a[A-GL-P]#[!c-e]")
?Like("BAT123khg","B?T*")
?Like("CAT123khg","B?T*")
?Like("Combine(10, 20) = 30", "*(*?,*?)*=*#")
|
|