Documentation ¶
Overview ¶
Package glob contains an implementation for a globbing algorithm that uses a intermediate bytecode representation to allow efficient reuse of single pattern. The implementation supports any rune as a wildcard.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Default = PatternDescription{Wildcard: '*'}
Default is a PatternDescription with wildcard '*'
var SQLLike = PatternDescription{Wildcard: '%'}
SQLLike is a PatternDescription with wildcard '%'
Functions ¶
func Glob ¶
Glob is an auxiliary function that returns whether the given pattern as interpreted by the Default PatternDescription matches the given string.
For efficiency reasons, it is better to build a globber and reuse it than to call this function multiple times if the pattern doesn't change. Each call of this function recompiles the pattern to a new globber.
Example ¶
package main import ( "bitbucket.org/ragnara/glob" "fmt" ) func main() { testdata := []string{ "cat", "dog", "bird", "fish", "lizard", "hedgehog", "fox", } for _, s := range testdata { if glob.Glob(s, "*i*") { fmt.Println(s, "contains an 'i'") } } }
Output: bird contains an 'i' fish contains an 'i' lizard contains an 'i'
Types ¶
type Globber ¶
type Globber struct {
// contains filtered or unexported fields
}
Globber matches strings using a precompiled pattern.
func New ¶
func New(pattern string, description PatternDescription) Globber
New creates a new globber by compiling a pattern according to the given PatternDescription.
func (Globber) Glob ¶
Glob returns whether the globbers pattern matches the given string.
Example ¶
package main import ( "bitbucket.org/ragnara/glob" "fmt" ) func main() { testdata := []string{ "cat", "dog", "bird", "fish", "lizard", "hedgehog", "fox", } endingWithDGlobber := glob.New("*d", glob.Default) for _, s := range testdata { if endingWithDGlobber.Glob(s) { fmt.Println(s, "ends with a 'd'") } } }
Output: bird ends with a 'd' lizard ends with a 'd'
type PatternDescription ¶
type PatternDescription struct { //Wildcard is the rune that is supposed to match 0..n runes. Wildcard rune }
PatternDescription describes the matching semantics of the pattern language.