keypattern

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractVars

func ExtractVars(expression string) [][]string

ExtractVars from the string expression Return data: [["{{key1}}", "key1"], ["{{key2}}", "key2"]]

Types

type ExecContext

type ExecContext map[string]string

func (ExecContext) Get

func (c ExecContext) Get(key string) any

type FMatcher

type FMatcher func(s string) (string, int)

FMatcher defines matching function

type Matcher

type Matcher interface {
	Match(s string, ectx ExecContext) (offset int)
}

func NewConstMatcher

func NewConstMatcher(cval string) Matcher

NewConstMatcher defines constant part of the pattern

func NewVarMatcher

func NewVarMatcher(name string, matcher FMatcher) Matcher

NewVarMatcher for the specific variable in the pattern

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

Pattern matcher type

func NewPattern

func NewPattern(matchers ...Matcher) *Pattern

NewPattern object by matchers

func NewPatternFromExpression

func NewPatternFromExpression(expression string) *Pattern

NewPatternFromExpression parse expression {{varname}} - variable definition in the pattern Example:

posts_{{id}}

func (*Pattern) Format

func (p *Pattern) Format(vals ValueGetter) string

func (*Pattern) Keys

func (p *Pattern) Keys() []string

Keys of the pattern

func (*Pattern) Match

func (p *Pattern) Match(s string, ectx ExecContext) bool

Match input string with the pattern

func (*Pattern) String

func (p *Pattern) String() string

type ValueGetter

type ValueGetter interface {
	Get(key string) any
}

type ValueType

type ValueType int
const (
	ConstValueType ValueType = 1
	VarValueType   ValueType = 2
)

Jump to

Keyboard shortcuts

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