Documentation
¶
Overview ¶
Package glob implements very simple glob pattern matching used in various parts of the Matrix spec, such as push rules and moderation policy lists.
See https://spec.matrix.org/v1.11/appendices/#glob-style-matching for more info.
Index ¶
- func Simplify(pattern string) string
- func SplitPattern(pattern string) []string
- func ToRegexPattern(pattern string, buf swWriter) error
- func ToSQL(pattern string) string
- type ContainsGlob
- type ExactGlob
- type Glob
- type PrefixAndSuffixGlob
- type PrefixGlob
- type PrefixSuffixAndContainsGlob
- type RegexGlob
- type SuffixGlob
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SplitPattern ¶
func ToRegexPattern ¶ added in v0.8.5
ToRegexPattern converts a glob pattern to a regex pattern and writes it to the given buffer.
Only errors returned by the Write calls are returned by this function (so if a non-erroring writer is used, this function will always return nil).
Types ¶
type ContainsGlob ¶
type ContainsGlob string
ContainsGlob is the result of Compile when the pattern has two `*`s, one at the beginning and one at the end. It uses strings.Contains to match.
When there are exactly two `*`s, but they're not surrounding the string, the pattern is compiled as a PrefixSuffixAndContainsGlob instead.
func (ContainsGlob) Match ¶
func (cg ContainsGlob) Match(s string) bool
type ExactGlob ¶
type ExactGlob string
ExactGlob is the result of Compile when the pattern contains no glob characters. It uses a simple string comparison to match.
type Glob ¶
func Compile ¶
Compile compiles a glob pattern into an object that can be used to efficiently match strings against the pattern.
Simple globs will be converted into prefix/suffix/contains checks, while complicated ones will be compiled as regex.
func CompileSimple ¶
CompileSimple compiles a glob pattern into one of the non-regex forms.
If the pattern can't be compiled into a simple form, it returns nil.
func CompileWithImplicitContains ¶
CompileWithImplicitContains is a wrapper for Compile which will replace exact matches with contains matches. i.e. if the pattern has no wildcards, it will be treated as if it was surrounded in asterisks (`foo` -> `*foo*`).
type PrefixAndSuffixGlob ¶
PrefixAndSuffixGlob is the result of Compile when the pattern only has one `*` in the middle.
func (PrefixAndSuffixGlob) Match ¶
func (psg PrefixAndSuffixGlob) Match(s string) bool
type PrefixGlob ¶
type PrefixGlob string
PrefixGlob is the result of Compile when the pattern only has one `*` at the end. It uses strings.HasPrefix to match.
func (PrefixGlob) Match ¶
func (pg PrefixGlob) Match(s string) bool
type PrefixSuffixAndContainsGlob ¶
PrefixSuffixAndContainsGlob is the result of Compile when the pattern has two `*`s which are not surrounding the rest of the pattern.
func (PrefixSuffixAndContainsGlob) Match ¶
func (psacg PrefixSuffixAndContainsGlob) Match(s string) bool
type RegexGlob ¶
type RegexGlob struct {
// contains filtered or unexported fields
}
func CompileRegex ¶
CompileRegex compiles the given glob pattern into a regex pattern.
If you want the raw regex string, use ToRegexPattern instead
type SuffixGlob ¶
type SuffixGlob string
SuffixGlob is the result of Compile when the pattern only has one `*` at the beginning. It uses strings.HasSuffix to match.
func (SuffixGlob) Match ¶
func (sg SuffixGlob) Match(s string) bool