luci: go.chromium.org/luci/common/data/text/pattern Index | Files

package pattern

import "go.chromium.org/luci/common/data/text/pattern"

Package pattern implements lightweight parsable string patterns.

Index

Package Files

constant.go exact.go pattern.go regexp.go

type Pattern Uses

type Pattern interface {
    // String returns the definition of the pattern parsable by Parse.
    String() string
    // Match returns true if s matches this pattern, otherwise false.
    Match(s string) bool
}

Pattern can either match or not match a string.

var (
    // Any matches anything.
    Any Pattern
    // None matches nothing.
    None Pattern
)

func Exact Uses

func Exact(s string) Pattern

Exact returns a pattern that matches s only.

func MustParse Uses

func MustParse(s string) Pattern

MustParse parses the pattern according to the specification of Parse. In addition, it panics if there is an error in parsing the given string as a pattern.

See Parse for more details.

func Parse Uses

func Parse(s string) (Pattern, error)

Parse parses a pattern.

Ordered by precedence, s can be:

- "": matches nothing
- "*": matches anything
- "<S>" where S does not have a colon: same as "exact:<S>"
- "exact:<S>": matches only string S
- "text:<S>": same as "exact:<S>" for backward compatibility
- "regex:<E>": matches all strings matching regular expression E. If E
  does not start/end with ^/$, they are added automatically.

Anything else will cause an error.

func Regexp Uses

func Regexp(expr *regexp.Regexp) Pattern

Regexp returns a regular expression-based pattern.

Package pattern imports 3 packages (graph) and is imported by 2 packages. Updated 2018-12-18. Refresh now. Tools for package owners.