commandbox.system.modules.globber.models

Class PathPatternMatcher

lucee.Component
    extended by commandbox.system.modules.globber.models.PathPatternMatcher

Copyright Since 2014 by Ortus Solutions, Corp www.coldbox.org | www.ortussolutions.com I am a utility to match file system path patterns End a pattern with a slash to only match a directory. Start a pattern with a slash to start in the root. Ex: - foo will match any file or folder in the directory tree - /foo will only match a file or folder in the root - foo/ will only match a directory anywhere in the directory tree - /foo/ will only match a folder in the root Use a single * to match zero or more characters INSIDE a file or folder name (won't match a slash) Ex: - foo* will match any file or folder starting with "foo" - foo*.txt will match any file or folder starting with "foo" and ending with .txt - *foo will match any file or folder ending with "foo" - a/* /z will match a/b/z but not a/b/c/z Use a double ** to match zero or more characters including slashes. This allows a pattern to span directories Ex: - a/** /z will match a/z and a/b/z and a/b/c/z A question mark matches a single non-slash character - /h?t matches hat but not ham or h/t

Class Attributes:
  • singleton
  •  
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
  • author : Brad Wood
  •  
    Constructor Summary
    init()
    Method Summary
    boolean isExclusion(string pattern)
    boolean matchPattern(string pattern, string path, [boolean exact='false'])
         Match a single path to a single pattern.
    boolean matchPatterns(array patterns, string path, [boolean exact='false'])
         Match an array of patterns against a single path.
    any normalizeSlashes([string path])
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init()


    Method Detail

    isExclusion

    public boolean isExclusion(string pattern)

    Parameters:
    pattern

    matchPattern

    public boolean matchPattern(string pattern, string path, [boolean exact='false'])

    Match a single path to a single pattern. Returns true if the path matches the pattern, otherwise false. The "exact" param is because Globber has different use cases. For example, when used for things like ignore lists a pattern not preceded by a slash should match directories and files recursibley, any level deep. But when used for a directory listing, it's expected to use ** /pattern/ ** to match deep folder. A pattern like foo must also match the entire file or folder name, not a partial name unless explicitly passed as *foo, foo*, or *foo*

    Parameters:
    pattern - The pattern to match against the path
    path - The file system path to test. Can be a file or directory. Direcories MUST end with a trailing slash
    exact - True if the full path needs to match. False to match inside a path.

    matchPatterns

    public boolean matchPatterns(array patterns, string path, [boolean exact='false'])

    Match an array of patterns against a single path. Returns true if at least one pattern matches, otherwise false.

    Parameters:
    patterns - An array of patterns to match against the path
    path - The file system path to test. Can be a file or directory. Direcories MUST end with a trailing slash
    exact

    normalizeSlashes

    public any normalizeSlashes([string path])

    Parameters:
    path