Documentation ¶
Overview ¶
Package rxp is an experiment in doing regexp-like things, without actually using regexp to do the work
Index ¶
- Constants
- Variables
- func ParseFlags(flags ...string) (Reps, Flags)
- func RuneIsALNUM(r rune) bool
- func RuneIsALPHA(r rune) bool
- func RuneIsASCII(r rune) bool
- func RuneIsBLANK(r rune) bool
- func RuneIsCNTRL(r rune) bool
- func RuneIsDIGIT(r rune) bool
- func RuneIsGRAPH(r rune) bool
- func RuneIsLOWER(r rune) bool
- func RuneIsPRINT(r rune) bool
- func RuneIsPUNCT(r rune) bool
- func RuneIsSPACE(r rune) bool
- func RuneIsSpace(r rune) bool
- func RuneIsUPPER(r rune) bool
- func RuneIsWord(r rune) bool
- func RuneIsXDIGIT(r rune) bool
- type AsciiNames
- type Flags
- func (f Flags) AnyCase() bool
- func (f Flags) Capture() bool
- func (f Flags) DotNL() bool
- func (f Flags) Has(flag Flags) bool
- func (f Flags) Less() bool
- func (f Flags) Matched() bool
- func (f Flags) Merge(other Flags) Flags
- func (f Flags) Multiline() bool
- func (f Flags) Negated() bool
- func (f Flags) OneOrMore() bool
- func (f Flags) Set(flag Flags) Flags
- func (f Flags) String() string
- func (f Flags) Unset(flag Flags) Flags
- func (f Flags) ZeroOrMore() bool
- func (f Flags) ZeroOrOne() bool
- type InputReader
- func (rb *InputReader) Bytes(index, count int) (slice []byte)
- func (rb *InputReader) End(index int) (end bool)
- func (rb *InputReader) Get(index int) (r rune, size int, ok bool)
- func (rb *InputReader) Invalid(index int) (invalid bool)
- func (rb *InputReader) Len() int
- func (rb *InputReader) Next(index int) (r rune, size int, ok bool)
- func (rb *InputReader) Prev(index int) (r rune, size int, ok bool)
- func (rb *InputReader) Ready(index int) (ready bool)
- func (rb *InputReader) Slice(index, count int) (slice []rune, size int)
- func (rb *InputReader) String(index, count int) string
- func (rb *InputReader) Valid(index int) (valid bool)
- type Matcher
- func A(flags ...string) Matcher
- func Alnum(flags ...string) Matcher
- func Alpha(flags ...string) Matcher
- func Ascii(flags ...string) Matcher
- func B(flags ...string) Matcher
- func BackRef(gid int, flags ...string) Matcher
- func Blank(flags ...string) Matcher
- func Caret(flags ...string) Matcher
- func Cntrl(flags ...string) Matcher
- func D(flags ...string) Matcher
- func Digit(flags ...string) Matcher
- func Dollar(flags ...string) Matcher
- func Dot(flags ...string) Matcher
- func Graph(flags ...string) Matcher
- func Group(options ...interface{}) Matcher
- func IsAtLeastSixDigits(flags ...string) Matcher
- func IsFieldKey(flags ...string) Matcher
- func IsFieldWord(flags ...string) Matcher
- func IsHash10(flags ...string) Matcher
- func IsKeyword(flags ...string) Matcher
- func IsUUID(flags ...string) Matcher
- func IsUnicodeRange(table *unicode.RangeTable, flags ...string) Matcher
- func Lower(flags ...string) Matcher
- func MakeMatcher(match Matcher, flags ...string) Matcher
- func NamedClass(name AsciiNames, flags ...string) Matcher
- func Not(options ...interface{}) Matcher
- func Or(options ...interface{}) Matcher
- func Print(flags ...string) Matcher
- func Punct(flags ...string) Matcher
- func R(characters string, flags ...string) Matcher
- func S(flags ...string) Matcher
- func Space(flags ...string) Matcher
- func Text(text string, flags ...string) Matcher
- func Upper(flags ...string) Matcher
- func W(flags ...string) Matcher
- func Word(flags ...string) Matcher
- func WrapMatcher(matcher RuneMatcher, flags ...string) Matcher
- func Xdigit(flags ...string) Matcher
- func Z(flags ...string) Matcher
- type Pattern
- func (p Pattern) A(flags ...string) Pattern
- func (p Pattern) Add(matcher Matcher) Pattern
- func (p Pattern) Alnum(flags ...string) Pattern
- func (p Pattern) Alpha(flags ...string) Pattern
- func (p Pattern) Ascii(flags ...string) Pattern
- func (p Pattern) B(flags ...string) Pattern
- func (p Pattern) BackRef(idx int, flags ...string) Pattern
- func (p Pattern) Blank(flags ...string) Pattern
- func (p Pattern) Caret(flags ...string) Pattern
- func (p Pattern) Cntrl(flags ...string) Pattern
- func (p Pattern) D(flags ...string) Pattern
- func (p Pattern) Digit(flags ...string) Pattern
- func (p Pattern) Dollar(flags ...string) Pattern
- func (p Pattern) Dot(flags ...string) Pattern
- func (p Pattern) FindAllBytes(input []byte, count int) (found [][]byte)
- func (p Pattern) FindAllBytesIndex(input []byte, count int) (found [][2]int)
- func (p Pattern) FindAllBytesSubmatch(input []byte, count int) (found [][][]byte)
- func (p Pattern) FindAllBytesSubmatchIndex(input []byte, count int) (found [][][2]int)
- func (p Pattern) FindAllRunes(input []rune, count int) (found [][]rune)
- func (p Pattern) FindAllRunesIndex(input []rune, count int) (found [][2]int)
- func (p Pattern) FindAllRunesSubmatch(input []rune, count int) (found [][][]rune)
- func (p Pattern) FindAllRunesSubmatchIndex(input []rune, count int) (found [][][2]int)
- func (p Pattern) FindAllString(input string, count int) (found []string)
- func (p Pattern) FindAllStringIndex(input string, count int) (found [][2]int)
- func (p Pattern) FindAllStringSubmatch(input string, count int) (found [][]string)
- func (p Pattern) FindAllStringSubmatchIndex(input string, count int) (found [][][2]int)
- func (p Pattern) FindBytes(input []byte) []byte
- func (p Pattern) FindBytesIndex(input []byte) (found [2]int)
- func (p Pattern) FindBytesSubmatch(input []byte) (found [][]byte)
- func (p Pattern) FindBytesSubmatchIndex(input []byte) (found [][2]int)
- func (p Pattern) FindRunes(input []rune) []rune
- func (p Pattern) FindRunesIndex(input []rune) (found [2]int)
- func (p Pattern) FindRunesSubmatch(input []rune) (found [][]rune)
- func (p Pattern) FindRunesSubmatchIndex(input []rune) (found [][2]int)
- func (p Pattern) FindString(input string) string
- func (p Pattern) FindStringIndex(input string) (found [2]int)
- func (p Pattern) FindStringSubmatch(input string) (found []string)
- func (p Pattern) FindStringSubmatchIndex(input string) (found [][2]int)
- func (p Pattern) Graph(flags ...string) Pattern
- func (p Pattern) Group(options ...interface{}) Pattern
- func (p Pattern) Lower(flags ...string) Pattern
- func (p Pattern) MatchBytes(input []byte) (ok bool)
- func (p Pattern) MatchRunes(input []rune) (ok bool)
- func (p Pattern) MatchString(input string) (ok bool)
- func (p Pattern) NamedClass(name AsciiNames, flags ...string) Pattern
- func (p Pattern) Not(options ...interface{}) Pattern
- func (p Pattern) Or(options ...interface{}) Pattern
- func (p Pattern) Print(flags ...string) Pattern
- func (p Pattern) Punct(flags ...string) Pattern
- func (p Pattern) R(characters string, flags ...string) Pattern
- func (p Pattern) RangeTable(table *unicode.RangeTable, flags ...string) Pattern
- func (p Pattern) ReplaceAllBytes(input []byte, replacements Replace[[]byte]) []byte
- func (p Pattern) ReplaceAllBytesFunc(input []byte, transform Transform[[]byte]) []byte
- func (p Pattern) ReplaceAllLiteralBytes(input []byte, replacement []byte) []byte
- func (p Pattern) ReplaceAllLiteralRunes(input []rune, replacement []rune) (replaced []rune)
- func (p Pattern) ReplaceAllLiteralString(input string, replacement string) string
- func (p Pattern) ReplaceAllRunes(input []rune, replacements Replace[[]rune]) (replaced []rune)
- func (p Pattern) ReplaceAllRunesFunc(input []rune, transform Transform[[]rune]) (replaced []rune)
- func (p Pattern) ReplaceAllString(input string, replacements Replace[string]) string
- func (p Pattern) ReplaceAllStringFunc(input string, transform Transform[string]) string
- func (p Pattern) S(flags ...string) Pattern
- func (p Pattern) Space(flags ...string) Pattern
- func (p Pattern) SplitBytes(input []byte, count int) (found [][]byte)
- func (p Pattern) SplitRunes(input []rune, count int) (found [][]rune)
- func (p Pattern) SplitString(input string, count int) (found []string)
- func (p Pattern) Text(text string, flags ...string) Pattern
- func (p Pattern) Upper(flags ...string) Pattern
- func (p Pattern) W(flags ...string) Pattern
- func (p Pattern) Word(flags ...string) Pattern
- func (p Pattern) Xdigit(flags ...string) Pattern
- func (p Pattern) Z(flags ...string) Pattern
- type Pipeline
- func (p Pipeline) Literal(search interface{}, text string) Pipeline
- func (p Pipeline) Process(input string) (output string)
- func (p Pipeline) Replace(search interface{}, replace Replace[string]) Pipeline
- func (p Pipeline) Substitute(search interface{}, transform Transform[string]) Pipeline
- func (p Pipeline) Transform(transform Transform[string]) Pipeline
- type Replace
- type Replacer
- type Reps
- type RuneMatcher
- type Stage
- type Transform
Constants ¶
const ( DefaultMinReps = 1 DefaultMaxReps = 1 )
Variables ¶
var LookupAsciiClass = map[AsciiNames]func(r rune) bool{ ALNUM: RuneIsALNUM, ALPHA: RuneIsALPHA, ASCII: RuneIsASCII, BLANK: RuneIsBLANK, CNTRL: RuneIsCNTRL, DIGIT: RuneIsDIGIT, GRAPH: RuneIsGRAPH, LOWER: RuneIsLOWER, PRINT: RuneIsPRINT, PUNCT: RuneIsPUNCT, SPACE: RuneIsSpace, UPPER: RuneIsUPPER, WORD: RuneIsWord, XDIGIT: RuneIsXDIGIT, }
Functions ¶
func ParseFlags ¶
ParseFlags parses a regexp-like option string into a Flags instance and two integers, the low and high range of repetitions
| Flags | Description | |---------|-----------------------------------------------------------------------------------------| | ^ | Invert the meaning of this match group | | m | Multiline mode Caret and Dollar match begin/end of line in addition to begin/end text | | s | DotNL allows Dot to match newlines (\n) | | i | AnyCase is case-insensitive matching of unicode text | | c | Capture allows this Matcher to be included in Pattern substring results | | * | zero or more repetitions, prefer more | | + | one or more repetitions, prefer more | | ? | zero or one repetition, prefer one | | {l,h} | range of repetitions, l minimum and up to h maximum, prefer more | | {l,} | range of repetitions, l minimum, prefer more | | {l} | range of repetitions, l minimum, prefer more | | *? | zero or more repetitions, prefer less | | +? | one or more repetitions, prefer less | | ?? | zero or one repetition, prefer zero | | {l,h}? | range of repetitions, l minimum and up to h maximum, prefer less | | {l,}? | range of repetitions, l minimum, prefer less | | {l}? | range of repetitions, l minimum, prefer less |
The flags presented above can be combined into a single string argument, or can be individually given to ParseFlags
Any parsing errors will result in a runtime panic
func RuneIsALNUM ¶
RuneIsALNUM returns true for alphanumeric characters [a-zA-Z0-9]
func RuneIsALPHA ¶
RuneIsALPHA returns true for alphanumeric characters [a-zA-Z]
func RuneIsASCII ¶
RuneIsASCII returns true for valid ASCII characters [\x00-\x7F]
func RuneIsBLANK ¶
RuneIsBLANK returns true for tab and space characters [\t ]
func RuneIsCNTRL ¶
RuneIsCNTRL returns true for control characters [\x00-\x1F\x7F]
func RuneIsGRAPH ¶
RuneIsGRAPH returns true for graphical characters [a-zA-Z0-9!"$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]
Note: upon the first use of RuneIsGRAPH, a lookup map is cached in a global variable and used for detecting the specific runes supported by the regexp [:graph:] class
func RuneIsLOWER ¶
RuneIsLOWER returns true for lowercase alphabetic characters [a-z]
func RuneIsPRINT ¶
RuneIsPRINT returns true for space and RuneIsGRAPH characters [ [:graph:]]
Note: uses RuneIsGRAPH
func RuneIsPUNCT ¶
RuneIsPUNCT returns true for punctuation characters [!-/:-@[-`{-~]
func RuneIsSPACE ¶
RuneIsSPACE returns true for empty space characters [\t\n\v\f\r ]
func RuneIsSpace ¶
RuneIsSpace returns true for space characters [\t\n\f\r ]
func RuneIsUPPER ¶
RuneIsUPPER returns true for lowercase alphabetic characters [A-Z]
func RuneIsWord ¶
RuneIsWord returns true for word characters [_a-zA-Z0-9]
func RuneIsXDIGIT ¶
RuneIsXDIGIT returns true for hexadecimal digits [z-fA-F0-9]
Types ¶
type AsciiNames ¶
type AsciiNames string
const ( ALNUM AsciiNames = "alnum" ALPHA AsciiNames = "alpha" ASCII AsciiNames = "ascii" BLANK AsciiNames = "blank" CNTRL AsciiNames = "cntrl" DIGIT AsciiNames = "digit" GRAPH AsciiNames = "graph" LOWER AsciiNames = "lower" PRINT AsciiNames = "print" PUNCT AsciiNames = "punct" SPACE AsciiNames = "space" UPPER AsciiNames = "upper" WORD AsciiNames = "word" XDIGIT AsciiNames = "xdigit" )
type InputReader ¶ added in v0.10.0
type InputReader struct {
// contains filtered or unexported fields
}
InputReader is an efficient rune based buffer
func NewInputReader ¶ added in v0.10.0
func NewInputReader[V []rune | []byte | string](input V) *InputReader
NewInputReader creates a new InputReader instance for the given input string
func (*InputReader) Bytes ¶ added in v0.10.0
func (rb *InputReader) Bytes(index, count int) (slice []byte)
Bytes returns the range of runes from start (inclusive) to end (exclusive) if the entire range is Ready
func (*InputReader) End ¶ added in v0.10.0
func (rb *InputReader) End(index int) (end bool)
End returns true if this index is exactly the input length, denoting the Dollar zero-width position
func (*InputReader) Get ¶ added in v0.10.0
func (rb *InputReader) Get(index int) (r rune, size int, ok bool)
Get returns the Ready rune at the given index position
func (*InputReader) Invalid ¶ added in v0.10.0
func (rb *InputReader) Invalid(index int) (invalid bool)
Invalid returns true if the given index position is less than zero or greater than or equal to the total length of the InputReader
func (*InputReader) Len ¶ added in v0.10.0
func (rb *InputReader) Len() int
Len returns the total number of runes in the InputReader
func (*InputReader) Next ¶ added in v0.10.0
func (rb *InputReader) Next(index int) (r rune, size int, ok bool)
Next returns the Ready rune after the given index position, or \0 if not Ready
func (*InputReader) Prev ¶ added in v0.10.0
func (rb *InputReader) Prev(index int) (r rune, size int, ok bool)
Prev returns the Ready rune before the given index position, or \0 if not Ready
The Prev is necessary because to find the previous rune to the given index, Prev must incrementally scan backwards up to four bytes, trying to read a rune without error with each iteration
func (*InputReader) Ready ¶ added in v0.10.0
func (rb *InputReader) Ready(index int) (ready bool)
Ready returns true if the given index position is greater than or equal to zero and less than the total length of the InputReader
func (*InputReader) Slice ¶ added in v0.10.0
func (rb *InputReader) Slice(index, count int) (slice []rune, size int)
Slice returns the range of runes from start (inclusive) to end (exclusive) if the entire range is Ready
func (*InputReader) String ¶ added in v0.10.0
func (rb *InputReader) String(index, count int) string
String returns the string of runes from start (inclusive) to end (exclusive) if the entire range is Ready
func (*InputReader) Valid ¶ added in v0.10.0
func (rb *InputReader) Valid(index int) (valid bool)
Valid returns true if the given index position is greater than or equal to zero and less than or equal to the total length of the InputReader
type Matcher ¶
type Matcher func(scope Flags, reps Reps, input *InputReader, index int, sm [][2]int) (scoped Flags, consumed int, proceed bool)
Matcher is a single string matching function
| Argument | Description | |----------|------------------------------------| | scope | current Flags for this iteration | | reps | min and max repetition settings | | input | input rune slice (do not modify!) | | index | current input rune index to match | | Return | Description | |----------|------------------------------------| | scoped | possibly modified sub-match scope | | consumed | number of runes matched from index | | proceed | success, keep matching for more |
func BackRef ¶ added in v0.8.0
BackRef is a Matcher equivalent to Perl backreferences where the gid argument is the match group to use
BackRef will panic if the gid argument is less than one
func Group ¶
func Group(options ...interface{}) Matcher
Group processes the list of Matcher instances, in the order they were given, and stops at the first one that does not match, discarding any consumed runes. If all Matcher calls succeed, all consumed runes are accepted together as this group (sub-sub-matches are not a thing in rxp)
func IsAtLeastSixDigits ¶ added in v0.10.0
IsAtLeastSixDigits creates a Matcher equivalent to:
(?:\A[0-9]{6,}\z)
func IsFieldKey ¶ added in v0.10.0
IsFieldKey creates a Matcher equivalent to:
(?:\b[a-zA-Z][-_a-zA-Z0-9]+?[a-zA-Z0-9]\b)
IsFieldKey is intended to validate CSS and HTML attribute key names such as "data-thing" or "some_value"
func IsFieldWord ¶ added in v0.10.0
IsFieldWord creates a Matcher equivalent to:
(?:\b[a-zA-Z0-9]+?[-_a-zA-Z0-9']*[a-zA-Z0-9]+\b|\b[a-zA-Z0-9]+\b)
func IsKeyword ¶ added in v0.10.0
IsKeyword is intended for Go-Enjin parsing of simple search keywords from user input and creates a Matcher equivalent to:
(?:\b[-+]?[a-zA-Z][-_a-zA-Z0-9']+?[a-zA-Z0-9]\b)
func IsUUID ¶ added in v0.10.0
IsUUID creates a Matcher equivalent to:
(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})
func IsUnicodeRange ¶
func IsUnicodeRange(table *unicode.RangeTable, flags ...string) Matcher
IsUnicodeRange creates a Matcher equivalent to the regexp \pN where N is a unicode character class, passed to IsUnicodeRange as a unicode.RangeTable instance
For example, creating a Matcher for a single braille character:
IsUnicodeRange(unicode.Braille)
func MakeMatcher ¶ added in v0.4.0
MakeMatcher creates a rxp standard Matcher implementation wrapped around a given RuneMatcher
func NamedClass ¶ added in v0.8.0
func NamedClass(name AsciiNames, flags ...string) Matcher
NamedClass creates a Matcher equivalent to the regexp [:AsciiNames:], see the AsciiNames constants for the list of supported ASCII class names
NamedClass will panic if given an invalid class name
func Not ¶
func Not(options ...interface{}) Matcher
Not processes all the matchers given, in the order they were given, stopping at the first one that succeeds and inverts the proceed return value
Not is equivalent to a negated character class in traditional regular expressions, for example:
[^xyza-f]
could be implemented as any of the following:
// slower due to four different matchers being present Not(Text("x"),Text("y"),Text("z"),R("a-f")) // better but still has two matchers Not(R("xyza-f")) // no significant difference from the previous Or(R("xyza-f"), "^") //< negation (^) flag // simplified to just one matcher present R("xyza-f", "^") //< negation (^) flag
here's the interesting bit about rxp though, if speed is really the goal, then the following would capture single characters matching [^xyz-af] with significant performance over MakeMatcher based matchers (use Pattern.Add to include the custom Matcher)
func(scope Flags, reps Reps, input *InputReader, index int, sm [][2]int) (scoped Flags, consumed int, proceed bool) { scoped = scope if r, size, ok := input.Get(index); ok { // test for [xyza-f] proceed = (r >= 'x' && r <= 'z') || (r >= 'a' && r <= 'f') // and invert the result proceed = !proceed if proceed { // true means the negation is a match // MatchedFlag is required, CaptureFlag optionally if needed scoped |= MatchedFlag | CaptureFlag // consume this rune's size if a capture group is needed // using size instead of just 1 will allow support for // accurate []rune, []byte and string processing consumed += size } return }
func Or ¶
func Or(options ...interface{}) Matcher
Or processes the list of Matcher instances, in the order they were given, and stops at the first one that returns a true next
Or accepts Pattern, Matcher and string types and will panic on all others
func R ¶ added in v0.8.0
R creates a Matcher equivalent to regexp character class ranges such as: [xyza-f] where x, y and z are individual runes to accept and a-f is the inclusive range of letters from lowercase a to lowercase f to accept
Note: do not include the [] brackets unless the intent is to actually accept those characters
func WrapMatcher ¶ added in v0.4.0
func WrapMatcher(matcher RuneMatcher, flags ...string) Matcher
WrapMatcher creates a Matcher using MakeMatcher and wrapping a RuneMatcher
type Pattern ¶
type Pattern []Matcher
Pattern is a list of Matcher functions, all of which must match, in the order present, in order to consider the Pattern to match
func ParseOptions ¶
ParseOptions accepts Pattern, Matcher and string options and recasts them into their specific types
ParseOptions will panic with any type other than Pattern, Matcher or string
func (Pattern) FindAllBytes ¶ added in v0.10.0
func (Pattern) FindAllBytesIndex ¶ added in v0.10.0
func (Pattern) FindAllBytesSubmatch ¶ added in v0.10.0
func (Pattern) FindAllBytesSubmatchIndex ¶ added in v0.10.0
func (Pattern) FindAllRunes ¶ added in v0.10.0
FindAllRunes returns a slice of strings containing all of the Pattern matches present in the input given, in the order the matches are found
func (Pattern) FindAllRunesIndex ¶ added in v0.10.0
FindAllRunesIndex returns a slice of starting and ending indices denoting each of the Pattern matches present in the input given
func (Pattern) FindAllRunesSubmatch ¶ added in v0.10.0
FindAllRunesSubmatch returns a slice of all Pattern matches (and any sub-matches) present in the input given
func (Pattern) FindAllRunesSubmatchIndex ¶ added in v0.10.0
FindAllRunesSubmatchIndex returns a slice of starting and ending points for all Pattern matches (and any sub-matches) present in the input given
func (Pattern) FindAllString ¶
FindAllString returns a slice of strings containing all of the Pattern matches present in the input given, in the order the matches are found
func (Pattern) FindAllStringIndex ¶
FindAllStringIndex returns a slice of starting and ending indices denoting each of the Pattern matches present in the input given
func (Pattern) FindAllStringSubmatch ¶
FindAllStringSubmatch returns a slice of all Pattern matches (and any sub-matches) present in the input given
func (Pattern) FindAllStringSubmatchIndex ¶ added in v0.4.0
FindAllStringSubmatchIndex returns a slice of starting and ending points for all Pattern matches (and any sub-matches) present in the input given
func (Pattern) FindBytesIndex ¶ added in v0.10.0
func (Pattern) FindBytesSubmatch ¶ added in v0.10.0
func (Pattern) FindBytesSubmatchIndex ¶ added in v0.10.0
func (Pattern) FindRunes ¶ added in v0.10.0
FindRunes returns the leftmost Pattern match within the input given
func (Pattern) FindRunesIndex ¶ added in v0.10.0
FindRunesIndex returns the leftmost Pattern match starting and ending indexes within the string given
func (Pattern) FindRunesSubmatch ¶ added in v0.10.0
FindRunesSubmatch returns a slice of strings holding the leftmost match of this Pattern and any of its sub-matches. FindRunesSubmatch returns nil if there was no match of this Pattern within the input given
func (Pattern) FindRunesSubmatchIndex ¶ added in v0.10.0
FindRunesSubmatchIndex returns a slice of starting and ending indices denoting the leftmost match of this Pattern and any of its sub-matches
func (Pattern) FindString ¶
FindString returns the leftmost Pattern match within the input given
func (Pattern) FindStringIndex ¶ added in v0.10.0
FindStringIndex returns the leftmost Pattern match starting and ending indexes within the string given
func (Pattern) FindStringSubmatch ¶
FindStringSubmatch returns a slice of strings holding the leftmost match of this Pattern and any of its sub-matches. FindStringSubmatch returns nil if there was no match of this Pattern within the input given
func (Pattern) FindStringSubmatchIndex ¶ added in v0.10.0
FindStringSubmatchIndex returns a slice of starting and ending indices denoting the leftmost match of this Pattern and any of its sub-matches
func (Pattern) MatchBytes ¶ added in v0.10.0
func (Pattern) MatchRunes ¶ added in v0.10.0
MatchRunes returns true if the input contains at least one match of this Pattern
func (Pattern) MatchString ¶
MatchString returns true if the input contains at least one match of this Pattern
func (Pattern) NamedClass ¶ added in v0.8.0
func (p Pattern) NamedClass(name AsciiNames, flags ...string) Pattern
func (Pattern) RangeTable ¶ added in v0.8.0
func (p Pattern) RangeTable(table *unicode.RangeTable, flags ...string) Pattern
func (Pattern) ReplaceAllBytes ¶ added in v0.10.0
func (Pattern) ReplaceAllBytesFunc ¶ added in v0.10.0
func (Pattern) ReplaceAllLiteralBytes ¶ added in v0.10.0
func (Pattern) ReplaceAllLiteralRunes ¶ added in v0.10.0
ReplaceAllLiteralRunes returns a copy of the input []rune with all Pattern matches replaced with the unmodified replacement text
func (Pattern) ReplaceAllLiteralString ¶ added in v0.10.0
ReplaceAllLiteralString returns a copy of the input string with all Pattern matches replaced with the unmodified replacement text
func (Pattern) ReplaceAllRunes ¶ added in v0.10.0
ReplaceAllRunes returns a copy of the input []rune with all Pattern matches replaced with text returned by the given Replace process
func (Pattern) ReplaceAllRunesFunc ¶ added in v0.10.0
ReplaceAllRunesFunc returns a copy of the input []rune with all Pattern matches replaced with the text returned by the given Transform function
func (Pattern) ReplaceAllString ¶
ReplaceAllString returns a copy of the input string with all Pattern matches replaced with text returned by the given Replace process
func (Pattern) ReplaceAllStringFunc ¶
ReplaceAllStringFunc returns a copy of the input string with all Pattern matches replaced with the text returned by the given Transform function
func (Pattern) SplitBytes ¶ added in v0.10.0
func (Pattern) SplitRunes ¶ added in v0.10.0
func (Pattern) SplitString ¶ added in v0.10.0
SplitString slices the input into substrings separated by the Pattern and returns a slice of the substrings between those Pattern matches
The slice returned by this method consists of all the substrings of input not contained in the slice returned by Pattern.FindAllString
Example:
s := regexp.MustCompile("a*").SplitString("abaabaccadaaae", 5) // s: ["", "b", "b", "c", "cadaaae"]
The count determines the number of substrings to return:
| Value Case | Description | |------------|-------------------------------------------------------------------| | count > 0 | at most count substrings; the last will be the un-split remainder | | count == 0 | the result is nil (zero substrings) | | count < 0 | all substrings |
type Pipeline ¶
type Pipeline []Stage
Pipeline is a list of stages for transforming strings in a single procedure
func (Pipeline) Literal ¶ added in v0.10.0
Literal appends a search Pattern and literal string replace operation to the Pipeline
The search argument can be a single Matcher function or a single Pattern
func (Pipeline) Process ¶
Process returns the output of a complete Pipeline transformation of the input string, and is obviously not a buildable method as it returns a string instead of an updated Pipeline
func (Pipeline) Replace ¶
Replace appends a search Pattern and Replace[string] operation to the Pipeline
The search argument can be a single Matcher function or a single Pattern
func (Pipeline) Substitute ¶ added in v0.10.0
Substitute appends a search Pattern and Transform[string] operation to the Pipeline
The search argument can be a single Matcher function or a single Pattern
type Replace ¶
Replace is a Replacer pipeline
func (Replace[V]) ToLower ¶
ToLower is a convenience method which, based on Replace type, will use one of the following methods to lower-case all the lower-case-able values
| Type | Function | |--------|-----------------| | []rune | unicode.ToLower | | []byte | bytes.ToLower | | string | strings.ToLower |
func (Replace[V]) ToUpper ¶
ToUpper is a convenience method which, based on Replace type, will use one of the following methods to upper-case all the upper-case-able values
| Type | Function | |--------|-----------------| | []rune | unicode.ToUpper | | []byte | bytes.ToUpper | | string | strings.ToUpper |
func (Replace[V]) WithLiteral ¶ added in v0.10.0
WithLiteral replaces matches with the literal value given
func (Replace[V]) WithReplace ¶
WithReplace replaces matches using a Replacer function
func (Replace[V]) WithTransform ¶
WithTransform replaces matches with a Transform function
type Replacer ¶ added in v0.10.0
type Replacer[V []rune | []byte | string] func(input *InputReader, captured [][2]int, modified V) (replaced V)
Replacer is a Replace processor function
The captured argument is the result of the Pattern match process and is composed of the entire matched text as the first item in the captured list, and any Pattern capture groups following
The modified string argument is the output of the previous Replacer in the Replace process, or the original matched input text if this is the first Replacer in the process
type Reps ¶ added in v0.2.0
type Reps []int
func (Reps) IsNil ¶ added in v0.4.0
IsNil returns true if the length of the Reps int slice is not at least two
func (Reps) Max ¶ added in v0.2.0
Max returns the maximum number of repetitions, or the DefaultMaxReps for nil instances
func (Reps) Min ¶ added in v0.2.0
Min returns the minimum number of repetitions, or the DefaultMinReps for nil instances
type RuneMatcher ¶
RuneMatcher is the signature for the basic character matching functions such as RuneIsWord
Implementations are expected to operate using the least amount of CPU instructions possible
type Stage ¶
type Stage struct { // Search is a Pattern of text, used with Replace to modify the matching // text Search Pattern Replace Replace[string] Transform Transform[string] }
Stage is one phase of a text replacement Pipeline and receives an input string from the previous stage (or the initial input text) and returns the output provided to the next stage (or is finally returned to the caller)
func (Stage) Process ¶
Process is the Pipeline processor method for a Stage
If there is a Search Pattern present, and there is at least one Replacer functions present, then the process returns a Search Pattern.ReplaceAllString
If there is a Search Pattern present, and there are no Replacer functions present, then the process returns a Search Pattern.ReplaceAllStringFunc
Source Files ¶
- rxp-flags-reps.go
- rxp-flags.go
- rxp-input-reader.go
- rxp-internals.go
- rxp-matcher.go
- rxp-matchers-common.go
- rxp-matchers-compositors.go
- rxp-matchers-perl.go
- rxp-matchers-zero.go
- rxp-pattern-builder.go
- rxp-pattern-bytes.go
- rxp-pattern-runes.go
- rxp-pattern-string.go
- rxp-pattern.go
- rxp-pipeline-stage.go
- rxp-pipeline.go
- rxp-replace.go
- rxp-rune-matchers-ascii-names.go
- rxp-rune-matchers-ascii.go
- rxp-rune-matchers-perl.go
- rxp.go