wildmatch: github.com/git-lfs/wildmatch Index | Files

package wildmatch

import "github.com/git-lfs/wildmatch"

package Wildmatch is an implementation of Git's wildmatch.c-style pattern matching.

Wildmatch patterns are comprised of any combination of the following three components:

- String literals. A string literal is "foo", or "foo\*" (matching "foo",
  and "foo\", respectively). In general, string literals match their exact
  contents in a filepath, and cannot match over directories unless they
  include the operating system-specific path separator.

- Wildcards. There are three types of wildcards:

   - Single-asterisk ('*'): matches any combination of characters, any
     number of times. Does not match path separators.

   - Single-question mark ('?'): matches any single character, but not a
     path separator.

   - Double-asterisk ('**'): greedily matches any number of directories.
     For example, '**/foo' matches '/foo', 'bar/baz/woot/foot', but not
     'foo/bar'. Double-asterisks must be separated by filepath separators
     on either side.

- Character groups. A character group is composed of a set of included and
  excluded character types. The set of included character types begins the
  character group, and a '^' or '!' separates it from the set of excluded
  character types.

  A character type can be one of the following:

    - Character literal: a single character, i.e., 'c'.

    - Character group: a group of characters, i.e., '[:alnum:]', etc.

    - Character range: a range of characters, i.e., 'a-z'.

A Wildmatch pattern can be any combination of the above components, in any ordering, and repeated any number of times.

Index

Package Files

package.go wildmatch.go wildmatch_nocasefold.go

Variables

var (
    // Basename allows the receiving Wildmatch to match paths where the
    // pattern matches only the basename of the path when the pattern does
    // not contain directory separators.
    //
    // If the pattern contains directory separators, or if this option is
    // not given, the entire path will be matched.
    Basename opt = func(w *Wildmatch) {
        w.basename = true
    }

    // CaseFold allows the receiving Wildmatch to match paths with
    // different case structuring as in the pattern.
    CaseFold opt = func(w *Wildmatch) {
        w.caseFold = true
    }

    // GitAttributes augments the functionality of the matching algorithm
    // to match behavior of git when working with .gitattributes files.
    GitAttributes opt = func(w *Wildmatch) {
        w.gitattributes = true
    }

    // SystemCase either folds or does not fold filepaths and patterns,
    // according to whether or not the operating system on which Wildmatch
    // runs supports case sensitive files or not.
    SystemCase opt
)

type MatchOpts Uses

type MatchOpts struct {
    IsDirectory bool
}

type Wildmatch Uses

type Wildmatch struct {
    // contains filtered or unexported fields
}

Wildmatch implements pattern matching against filepaths using the format described in the package documentation.

For more, see documentation for package 'wildmatch'.

func NewWildmatch Uses

func NewWildmatch(p string, opts ...opt) *Wildmatch

NewWildmatch constructs a new Wildmatch instance which matches filepaths according to the given pattern and the rules for matching above.

If the pattern is malformed, for instance, it has an unclosed character group, escape sequence, or character class, NewWildmatch will panic().

func (*Wildmatch) Match Uses

func (w *Wildmatch) Match(t string) bool

Match returns true if and only if the pattern matched by the receiving Wildmatch matches the entire filepath "t".

func (*Wildmatch) MatchWithOpts Uses

func (w *Wildmatch) MatchWithOpts(t string, opt MatchOpts) bool

func (*Wildmatch) String Uses

func (w *Wildmatch) String() string

String implements fmt.Stringer and returns the receiver's pattern in the format specified above.

Package wildmatch imports 5 packages (graph) and is imported by 4 packages. Updated 2020-04-06. Refresh now. Tools for package owners.