PBDLL ... anything like VB's 'Like' operator ?? 
Author Message
 PBDLL ... anything like VB's 'Like' operator ??

Is there anything in PBDLL 2.0 that's similar to VisualBASIC's 'Like'
operator ??   If not, does anyone have a look-a-like Function ??
Maybe something out of a file find program ??

To send me Email ... remove any (anti-spam) X's in my address



Mon, 26 Nov 2001 03:00:00 GMT  
 PBDLL ... anything like VB's 'Like' operator ??

Quote:

> Is there anything in PBDLL 2.0 that's similar to VisualBASIC's 'Like'
> operator ??   If not, does anyone have a look-a-like Function ??
> Maybe something out of a file find program ??

%FALSE = 0
%TRUE  = NOT %FALSE
'=============================================================================
'
' Like Function for PB/DLL
'   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



        FUNCTION = %TRUE
      END IF
      EXIT FUNCTION
    END IF


      CASE 0  'NUL  pre-mature end
        EXIT FUNCTION

      CASE 35 '#    match a single numeric digit

          EXIT FUNCTION
        END IF

      CASE 42 '*
        INCR y                 ' next char in expression
        DO

            EXIT DO            ' yes exit

            EXIT DO            ' yes exit
          END IF
          INCR x               ' next char in source string
        LOOP


            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


          Match = %FALSE
          INCR y
        END IF

        DO

            EXIT FUNCTION

            EXIT FUNCTION

            DECR y             ' move to previous char in expression

            y = y + 2          ' move to next char in expression

            DECR y             ' restore current char in expression
            IF (PrevChar = 91) OR (PrevChar = 33) OR (NextChar = 93) THEN

                IF Match = %FALSE THEN  'if matching is false, exit
                  EXIT FUNCTION
                ELSE
                    EXIT DO
                END IF
              END IF
            ELSE

                IF Match = %FALSE THEN
                  EXIT FUNCTION
                ELSE
                  EXIT DO
                END IF
              ELSE
                INCR y
              END IF
            END IF

            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

            EXIT DO

            EXIT FUNCTION
          END IF
          INCR y
        LOOP

      CASE ELSE

          EXIT DO
        END IF

    END SELECT

    INCR x    ' next char in source string
    INCR y    ' next char in expression

  LOOP

END FUNCTION

--
PowerBASIC, Inc.      | 800-780-7707 Sales | "We put the Power in Basic!"
316 Mid Valley Center | 831-659-8000 Voice | http://www.powerbasic.com



Mon, 26 Nov 2001 03:00:00 GMT  
 PBDLL ... anything like VB's 'Like' operator ??

Quote:

>Is there anything in PBDLL 2.0 that's similar to VisualBASIC's 'Like'
>operator ??   If not, does anyone have a look-a-like Function ??
>Maybe something out of a file find program ??

>To send me Email ... remove any (anti-spam) X's in my address

What is the 'LIKE' function used for ?
Can you give us some examples ?

Thanks

IanMc



Mon, 26 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ( 2.31.New operators: 'eq', 'ne', 'last', '..' ) ?

2. Substitute for VB command LoadImage('filename')

3. overloading '!' operator

4. Proposal: new operator: '<-' (for assignments)

5. overriding operator 'or'

6. GNAT-Problem '+'-operator with Count

7. Operator overloading and 'sum' intrinsic function

8. Overloaded '=' operator on a structured type

9. 'in' operator

10. '->' operator

11. the 'in' operator and class instances

12. the 'in' operator and class instances

 

 
Powered by phpBB® Forum Software