pattern

package
v0.0.0-...-0921c0e Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package pattern handles parsing and matching SQL LIKE-style glob patterns.

Index

Constants

View Source
const (
	DefaultEscapeChar = '\\'
)

Variables

View Source
var (
	ErrIllegalEscapeChar = verror.Register("v.io/v23/query/pattern.IllegalEscapeChar", verror.NoRetry, "{1:}{2:} '%' and '_' cannot be used as escape characters")
	ErrInvalidEscape     = verror.Register("v.io/v23/query/pattern.InvalidEscape", verror.NoRetry, "{1:}{2:} only '%', '_', and the escape character are allowed to be escaped, found '\\{3}'")
)

Functions

func Escape

func Escape(s string) string

Escape escapes a literal string for inclusion in a LIKE-style pattern assuming '\' as escape character. See EscapeWithEscapeChar().

func EscapeWithEscapeChar

func EscapeWithEscapeChar(s string, escChar rune) string

EscapeWithEscapeChar escapes a literal string for inclusion in a LIKE-style pattern. It inserts escChar before each '_', '%', and escChar in the string.

func NewErrIllegalEscapeChar

func NewErrIllegalEscapeChar(ctx *context.T) error

NewErrIllegalEscapeChar returns an error with the ErrIllegalEscapeChar ID.

func NewErrInvalidEscape

func NewErrInvalidEscape(ctx *context.T, escaped string) error

NewErrInvalidEscape returns an error with the ErrInvalidEscape ID.

Types

type Pattern

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

Pattern is a parsed LIKE-style glob pattern.

func Parse

func Parse(pattern string) (*Pattern, error)

Parse parses a LIKE-style glob pattern assuming '\' as escape character. See ParseWithEscapeChar().

func ParseWithEscapeChar

func ParseWithEscapeChar(pattern string, escChar rune) (*Pattern, error)

ParseWithEscapeChar parses a LIKE-style glob pattern. Supported wildcards are '_' (match any one character) and '%' (match zero or more characters). They can be escaped by escChar; escChar can also escape itself. '_' and '%' cannot be used as escChar; '\x00' escChar disables escaping.

func (*Pattern) FixedPrefix

func (p *Pattern) FixedPrefix() (string, bool)

FixedPrefix returns the unescaped fixed prefix that all matching strings must start with, and whether the prefix is the whole pattern.

func (*Pattern) MatchString

func (p *Pattern) MatchString(s string) bool

MatchString returns true iff the pattern matches the entire string.

Jump to

Keyboard shortcuts

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