Documentation ¶
Overview ¶
Package glob implements a glob/capture/replace library based on github.com/pachyderm/ohmyglob
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasGlobRunes ¶
HasGlobRunes scans a string for runes that indicate it's a glob pattern.
func HasTemplateRunes ¶
HasTemplateRunes scans a string for runes that indicate it's a template.
func IsGlobRune ¶
IsGlobRune checks if a rune is a special glyph on the Glob syntax
func IsTemplateRune ¶
IsTemplateRune checks if a rune is a special glyph on the Template syntax
Types ¶
type Glob ¶
type Glob struct {
// contains filtered or unexported fields
}
Glob represents a compiled glob pattern
func Compile ¶
Compile creates a Glob for the given pattern and separators.
The pattern syntax is:
pattern: { term } term: `*` matches any sequence of non-separator characters `**` matches any sequence of characters `?` matches any single non-separator character `[` [ `!` ] { character-range } `]` character class (must be non-empty) `{` pattern-list `}` pattern alternatives c matches character c (c != `*`, `**`, `?`, `\`, `[`, `{`, `}`) `\` c matches character c character-range: c matches character c (c != `\\`, `-`, `]`) `\` c matches character c lo `-` hi matches character c for lo <= c <= hi pattern-list: pattern { `,` pattern } comma-separated (without spaces) patterns captures: `(` { `|` pattern } `)` `@(` { `|` pattern } `)` match and capture one of pipe-separated sub-patterns `*(` { `|` pattern } `)` match and capture any number of the pipe-separated sub-patterns `+(` { `|` pattern } `)` match and capture one or more of the pipe-separated sub-patterns `?(` { `|` pattern } `)` match and capture zero or one of the pipe-separated sub-patterns `!(` { `|` pattern } `)` match and capture anything except one of the pipe-separated sub-patterns
func MustCompile ¶
MustCompile does the same as Compile but panics if there is an error.
func (*Glob) Capture ¶
Capture returns the list of sub-expressions captured by the pattern against the given fixture, and also indicates if there was a match at all.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is the compiled representation of a replace pattern
func CompileTemplate ¶
CompileTemplate creates a Template for the given template
Syntax is very simple. `${n}` and `$n` to indicate position in the captures slice, and `$$` to escape a literal `$`.
Escaping `$` isn't required when followed by anything other than a number or a `{`.
Captures are counted starting with 1.