BOOLEAN = LONG
в PB нет оператора LIKE, но есть вот такое чудо от Dave Navarro.
Вообще, если поискать на форуме PB, то можно найти много интересных кодов от этого товарища...
- Код: Выделить всё
' http://www.powerbasic.com/support/forums/Forum2/HTML/000011.html
%FALSE = 0
%TRUE = NOT %FALSE
'=============================================================================
'
' Like Function for PB/DLL 2.0
' Used to compare a source string with a string expression.
'
' Syntax
' result = Like(source_string, expression_pattern, case_sensitivity)
'
' Parameters
' source_string Target string to compare pattern against.
' expression_pattern Wildcard expression pattern:
' ? Any single character
' * Zero or more characters
' # Any single digit (0-9)
' [charlist] Any single character in 'charlist'
' [!charlist] Any single character not in 'charlist'
' case_sensitivity Toggle for case sensitivity (true or false)
'
' Note
' It is not exported because it is not compatible with
' Visual Basic strings, only PowerBASIC strings.
'
FUNCTION Like(BYVAL a AS STRING, BYVAL b AS STRING, _
BYVAL lCase AS INTEGER) AS INTEGER
DIM x AS BYTE PTR
DIM y AS BYTE PTR
DIM match AS INTEGER
DIM PrevChar AS BYTE
DIM NextChar AS BYTE
IF lCase THEN
a = a + CHR$(0)
b = b + CHR$(0)
ELSE
a = UCASE$(a + CHR$(0))
b = UCASE$(b + CHR$(0))
END IF
x = STRPTR(a)
y = STRPTR(b)
FUNCTION = %FALSE
DO
IF @x = 0 THEN
IF @y = 0 THEN
FUNCTION = %TRUE
END IF
EXIT FUNCTION
END IF
SELECT CASE @y
CASE 0 'NUL pre-mature end
EXIT FUNCTION
CASE 35 '# match a single numeric digit
IF (@x < 48) OR (@x > 57) THEN
EXIT FUNCTION
END IF
CASE 42 '*
INCR y ' next char in expression
DO
IF @x = @y THEN ' do they match?
EXIT DO ' yes exit
ELSEIF @x = 0 THEN ' end of source string?
EXIT DO ' yes exit
END IF
INCR x ' next char in source string
LOOP
IF @x = 0 THEN ' end of source string?
IF @y = 0 THEN ' also end of expression?
FUNCTION = %TRUE
END IF
EXIT FUNCTION
END IF
CASE 63 '? match any single char
' nothing, it's a match
CASE 91 '[
Match = %TRUE ' assume we have to match chars
INCR y ' next char in expression
IF @y = 33 THEN ' ! indicates do not match
Match = %FALSE
INCR y
END IF
DO
IF @y = 93 THEN ' ]
EXIT FUNCTION
ELSEIF @y = 0 THEN ' NUL
EXIT FUNCTION
ELSEIF @y = 45 THEN ' -
DECR y ' move to previous char in expression
PrevChar = @y ' save previous char
y = y + 2 ' move to next char in expression
NextChar = @y ' save next char
DECR y ' restore current char in expression
IF (PrevChar = 91) OR (PrevChar = 33) OR (NextChar = 93) THEN
IF @y = @x THEN
IF Match = %FALSE THEN 'if matching is false, exit
EXIT FUNCTION
ELSE
EXIT DO
END IF
END IF
ELSE
IF (@x >= PrevChar) AND (@x =< NextChar) THEN
IF Match = %FALSE THEN
EXIT FUNCTION
ELSE
EXIT DO
END IF
ELSE
INCR y
END IF
END IF
ELSEIF @y = @x THEN ' do they match?
IF Match = %FALSE THEN 'if matching is false, exit
EXIT FUNCTION
ELSE
EXIT DO
END IF
END IF
INCR y 'next char in expression
LOOP
DO 'find the closing bracket
IF @y = 93 THEN
EXIT DO
ELSEIF @y = 0 THEN
EXIT FUNCTION
END IF
INCR y
LOOP
CASE ELSE
IF @x <> @y THEN
EXIT DO
END IF
END SELECT
INCR x ' next char in source string
INCR y ' next char in expression
LOOP
END FUNCTION