Announcement

Collapse
No announcement yet.

Wildcard

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wildcard

    Some wild-card pattern search api...

    RtlIsNameInExpression: Determines whether a Unicode string matches the specified pattern.

    SymMatchString: Compares the specified string to the specified wildcard expression.

    And the old PathMatchSpec: Searches a string using a Microsoft MS-DOS wildcard match type.

    Pierre

    Code:
    #COMPILE EXE '#CC 5.07#
    #DIM ALL
    #INCLUDE "Win32Api.inc"
    
    TYPE UNICODE_STRINGa WORD 'Tt J.Roca
      Length        AS WORD
      MaximumLength AS WORD
      Buffer        AS STRING POINTER 'Unicode
    END TYPE
    
    DECLARE FUNCTION PathMatchSpec LIB "ShlWApi.dll" ALIAS "PathMatchSpecA" _
    (pszFile AS ASCIIZ, pszSpec AS ASCIIZ) AS LONG
    
    DECLARE FUNCTION RtlIsNameInExpression LIB "NtDll.dll" ALIAS "RtlIsNameInExpression" _
    (wsExpression AS UNICODE_STRINGa, wsName AS UNICODE_STRINGa, IgnoreCase AS LONG, OPT pUpcaseTable AS DWORD) AS LONG
    
    DECLARE FUNCTION SymMatchString LIB "ImageHlp.dll" ALIAS "SymMatchStringA" _
    (BYREF zString AS ASCIIZ, BYREF Expression AS ASCIIZ, BYVAL fCase AS LONG) AS LONG
    
    '_____________________________________________________________________________
    
    FUNCTION PBMAIN() AS LONG
     LOCAL UniStrPattern AS UNICODE_STRINGa
     LOCAL UniStrData    AS UNICODE_STRINGa
     LOCAL zData         AS ASCIIZ * %MAX_PATH
     LOCAL zExpression   AS ASCIIZ * %MAX_PATH
     LOCAL sPattern      AS STRING
     LOCAL sData         AS STRING
     LOCAL sUpcaseTable  AS STRING
     LOCAL pUpcaseTable  AS DWORD
     LOCAL SameCase      AS LONG
     LOCAL IgnoreCase    AS LONG
     LOCAL RetVal        AS LONG
    
     PRINT "Wildcard functions" : PRINT
    
     sPattern                    = UCODE$("AB?DEF")
     UniStrPattern.Length        = LEN(sPattern)
     UniStrPattern.MaximumLength = UniStrPattern.Length
     UniStrPattern.Buffer        = STRPTR(sPattern)
    
     sData                       = UCODE$("abCDEF")
     UniStrData.Length           = LEN(sData)
     UniStrData.MaximumLength    = UniStrData.Length
     UniStrData.Buffer           = STRPTR(sData)
    
     'sUpcaseTable = "..."
     'pUpcaseTable = STRPTR(sUpcaseTable)
     pUpcaseTable  = 0 'Use Windows default
     IgnoreCase    = %TRUE
    
     '1.If IgnoreCase is TRUE, Expression must be uppercase.
     '2.If this value is not supplied, the default system uppercase character table is used.
     '3.If only one of the string parameters has a length of zero, FsRtlIsNameInExpression returns FALSE.
     '  This means that "*" does not match a null string.
     '4.If both parameters are null strings, FsRtlIsNameInExpression returns TRUE.
    
     'The following are wildcard characters: *, ?, ANSI_DOS_STAR, ANSI_DOS_DOT, and ANSI_DOS_QM.
     '#define DOS_STAR [<]
     '#define DOS_QM   [>]
     '#define DOS_DOT  ["]
    
     RetVal = RtlIsNameInExpression(UniStrPattern, UniStrData, BYVAL IgnoreCase, BYVAL pUpcaseTable) 'Windows 7+
     PRINT "RtlIsNameInExpression " & STR$(RetVal) 'True mean a match
    
     zData       = "ABCD"
     zExpression = "abC?" 'The wildcard expression supports the inclusion of the * and ? characters.
     SameCase    = %FALSE 'TRUE
     RetVal      = SymMatchString(zData, zExpression, SameCase) 'XP+
     PRINT
     PRINT "SymMatchString" & STR$(RetVal) 'True mean a match
    
     RetVal = PathMatchSpec(zData, zExpression) 'Win 98/2000+
     PRINT
     PRINT "PathMatchSpec" & STR$(RetVal) 'True mean a match
    
     PRINT : PRINT "Type or click..." : MOUSE ON : MOUSE 3, UP : WAITKEY$
    
    END FUNCTION
    '______________________________________________________________________________
    '
    Last edited by Pierre Bellisle; 6 May 2017, 08:46 PM.

  • #2
    You filled in the Unicode strings incorrectly. Both Buffer's point to the sPattern string, plus Length & MaximumLength should be the byte count of the strings pointed to by Buffer, not the size of the unicode_string UDT. For static strings, RtlInitUnicodeString sets the Length to the byte length of the string except the NUL, and MaximumLength includes it.

    Comment


    • #3
      Yep,
      Also content in pattern and data was inverted.
      Code above updated.

      Pierre

      Comment


      • #4
        Regular Expressions?

        See Doc at REGEXPR ==> https://forum.powerbasic.com/forum/a...tement?t=56438

        MCM
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          i am looking for win32api for string not using a wildcard
          thanks

          Comment


          • #6
            i want to search as string with out a wild cards

            Comment


            • #7
              Could you give an example of what you're hoping for? Of the top, I suggest INSTR, and possibly TALLY.
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment

              Working...
              X