glob

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: MPL-2.0 Imports: 3 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Simplify

func Simplify(pattern string) string

func SplitPattern

func SplitPattern(pattern string) []string

func ToSQL

func ToSQL(pattern string) string

ToSQL converts a Matrix glob pattern to a SQL LIKE pattern.

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.

func (ExactGlob) Match

func (eg ExactGlob) Match(s string) bool

type Glob

type Glob interface {
	Match(string) bool
}

func Compile

func Compile(pattern string) Glob

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

func CompileSimple(pattern string) Glob

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

func CompileWithImplicitContains(pattern string) Glob

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

type PrefixAndSuffixGlob struct {
	Prefix string
	Suffix string
}

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

type PrefixSuffixAndContainsGlob struct {
	Prefix   string
	Suffix   string
	Contains string
}

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

func CompileRegex(pattern string) (*RegexGlob, error)

func (*RegexGlob) Match

func (rg *RegexGlob) Match(s string) bool

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL