pattern

package
v0.0.0-...-5105380 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

TODO: capture index (e.g. %1) TODO: balanced captures TODO: frontier patterns TODO: introduce opSave TODO: eliminate opClose TODO: pattern sets TODO: replace TODO: anchor tail $

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(text, expr string) (captures []string)

Match is like MatchIndex except that the capture are returned instead of the positions.

func MatchAll

func MatchAll(text, expr string, limit int) (captures [][]string)

MatchAll is like MatchIndexAll excepts that the capture string are returned instead of the positions.

func MatchIndex

func MatchIndex(text, expr string) (captures []int)

MatchIndex matches the first item in text to match the pattern expr. The matche is returned as a slice of integer offsets that points to the boundaries of any captures found in the match.

func MatchIndexAll

func MatchIndexAll(text, expr string, limit int) (captures [][]int)

MatchIndexAll matches all items in text that match the pattern expr upto limit (or all if limit is -1). The matches are returned as a two-dimensional slice of integer offsets that points to the boundaries of any captures found in the match.

func Replace

func Replace(text, expr string, repl Replacer) (string, int)

Replace replaces the first match of text in expr using the provided Replacer repl. On success, the replaced string and number of replacements is returned; Otherwise "", 0 is returned.

func ReplaceAll

func ReplaceAll(text, expr string, repl Replacer, limit int) (string, int)

ReplaceAll replaces all (or upto limit) matches of text in expr using the provided Replacer repl. The new string and number of replacements made is returned. If no match was made, "", 0 is returned.

Types

type Pattern

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

func Compile

func Compile(expr string) (*Pattern, error)

func MustCompile

func MustCompile(expr string) *Pattern

func (Pattern) Match

func (patt Pattern) Match(src string) (captures []string)

func (Pattern) MatchAll

func (patt Pattern) MatchAll(src string, limit int) (captures [][]string)

func (Pattern) MatchIndex

func (patt Pattern) MatchIndex(src string) (captures []int)

func (Pattern) MatchIndexAll

func (patt Pattern) MatchIndexAll(src string, limit int) (captures [][]int)

func (Pattern) Replace

func (patt Pattern) Replace(text string, repl Replacer) (string, int)

func (Pattern) ReplaceAll

func (patt Pattern) ReplaceAll(text string, repl Replacer, limit int) (string, int)

type Replacer

type Replacer interface {
	Replace(string) string
}

A Replacer replaces strings that matches a pattern.

Jump to

Keyboard shortcuts

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