github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/pkgpattern/pkgpattern.go (about)

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package pkgpattern
     6  
     7  // TreeCanMatchPattern(pattern)(name) reports whether
     8  // name or children of name can possibly match pattern.
     9  // Pattern is the same limited glob accepted by MatchPattern.
    10  func TreeCanMatchPattern(pattern string) func(name string) bool
    11  
    12  // MatchPattern(pattern)(name) reports whether
    13  // name matches pattern. Pattern is a limited glob
    14  // pattern in which '...' means 'any string' and there
    15  // is no other special syntax.
    16  // Unfortunately, there are two special cases. Quoting "go help packages":
    17  //
    18  // First, /... at the end of the pattern can match an empty string,
    19  // so that net/... matches both net and packages in its subdirectories, like net/http.
    20  // Second, any slash-separated pattern element containing a wildcard never
    21  // participates in a match of the "vendor" element in the path of a vendored
    22  // package, so that ./... does not match packages in subdirectories of
    23  // ./vendor or ./mycode/vendor, but ./vendor/... and ./mycode/vendor/... do.
    24  // Note, however, that a directory named vendor that itself contains code
    25  // is not a vendored package: cmd/vendor would be a command named vendor,
    26  // and the pattern cmd/... matches it.
    27  func MatchPattern(pattern string) func(name string) bool
    28  
    29  // MatchSimplePattern returns a function that can be used to check
    30  // whether a given name matches a pattern, where pattern is a limited
    31  // glob pattern in which '...' means 'any string', with no other
    32  // special syntax. There is one special case for MatchPatternSimple:
    33  // according to the rules in "go help packages": a /... at the end of
    34  // the pattern can match an empty string, so that net/... matches both
    35  // net and packages in its subdirectories, like net/http.
    36  func MatchSimplePattern(pattern string) func(name string) bool