Documentation ¶
Overview ¶
Package search provides language-sensitive string search functionality.
Index ¶
- type Option
- type Pattern
- func (p *Pattern) CommonPrefix(b []byte) []byte
- func (p *Pattern) CommonPrefixString(s string) []byte
- func (p *Pattern) Find(b []byte) []int
- func (p *Pattern) FindAll(b []byte) [][]int
- func (p *Pattern) FindAllString(s string) [][]int
- func (p *Pattern) FindLast(b []byte) []int
- func (p *Pattern) FindLastString(s string) []int
- func (p *Pattern) FindString(s string) []int
- func (p *Pattern) HasPrefix(b []byte) bool
- func (p *Pattern) HasPrefixString(s string) bool
- func (p *Pattern) HasSuffix(b []byte) bool
- func (p *Pattern) HasSuffixString(s string) bool
- func (p *Pattern) Match(b []byte) bool
- func (p *Pattern) MatchString(b []byte) bool
- type Search
- func (s *Search) CommonPrefix(a, b []byte) []byte
- func (s *Search) CommonPrefixString(a, b string) string
- func (s *Search) Compile(b []byte) *Pattern
- func (s *Search) CompileString(b string) *Pattern
- func (s *Search) Find(b, pat []byte) []int
- func (s *Search) FindAll(b, pat []byte) [][]int
- func (s *Search) FindAllString(str, pat string) [][]int
- func (s *Search) FindLast(b, pat []byte) []int
- func (s *Search) FindLastString(str, pat string) []int
- func (s *Search) FindString(str, pat string) []int
- func (s *Search) HasPrefix(str, prefix []byte) bool
- func (s *Search) HasPrefixString(str, prefix string) bool
- func (s *Search) HasSufix(str, suffix []byte) bool
- func (s *Search) HasSufixString(str, suffix string) bool
- func (s *Search) Match(a, b []byte) bool
- func (s *Search) MatchString(a, b string) bool
- func (s *Search) SetOptions(mask Option) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option int
An Option specifies a search-related feature.
const ( IgnoreCase Option = 1 << iota // Case-insensitive search. IgnoreDiacritics // Ignore diacritics. ("ö" == "o"). IgnoreWidth // Ignore full versus normal width. WholeWord // Only match at whole-word boundaries. Literal // Exact equivalence. Loose = IgnoreCase | IgnoreDiacritics | IgnoreWidth )
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern holds a preprocessed search pattern. On repeated use of a search pattern, it will be more efficient to use Pattern than the direct methods.
Example ¶
package main import ( "fmt" "golang.org/x/exp/locale/search" "golang.org/x/text/language" ) func main() { s := search.New(language.German) pat := s.CompileString("gruss") fmt.Println(pat.FindString("Schöne Gruße")) fmt.Println(pat.FindLastString("Schöne Gruße")) // TODO:Output: // [8 13] // [8 13] }
Output:
func (*Pattern) CommonPrefix ¶
CommonPrefix returns b[:n], where n is the largest value that satisfies p.Match(b[:n]).
func (*Pattern) CommonPrefixString ¶
CommonPrefixString returns s[:n], where n is the largest value that satisfies p.Match(s[:n]).
func (*Pattern) Find ¶
Find returns a two-element slice of integers defining the leftmost match of p in b. A return value of nil indicates no match.
func (*Pattern) FindAll ¶
FindAll returns a slice of successive matches of p in b, each represented by a two-element slice of integers. A return value of nil indicates no match.
func (*Pattern) FindAllString ¶
FindAllString returns a slice of successive matches of p in s, each represented by a two-element slice of integers. A return value of nil indicates no match.
func (*Pattern) FindLast ¶
FindLast returns a two-element slice of integers defining the rightmost match of p in b. A return value of nil indicates no match.
func (*Pattern) FindLastString ¶
FindLastString returns a two-element slice of integers defining the rightmost match of p in s. A return value of nil indicates no match.
func (*Pattern) FindString ¶
FindString returns a two-element slice of integers defining the leftmost match of p in s. A return value of nil indicates no match.
func (*Pattern) HasPrefixString ¶
HasPrefixString tests whether the string s begins with p.
func (*Pattern) HasSuffixString ¶
HasSuffixString tests whether the string s ends with p.
func (*Pattern) MatchString ¶
MatchString checks whether b is equivalent to p.
type Search ¶
type Search struct {
// contains filtered or unexported fields
}
Search provides language-sensitive search functionality.
Example ¶
package main import ( "fmt" "golang.org/x/exp/locale/search" "golang.org/x/text/language" ) func main() { p := func(x ...interface{}) { fmt.Println(x...) } s := search.New(language.English) s.SetOptions(search.IgnoreCase | search.IgnoreDiacritics) p(s.MatchString("A", "a")) p(s.MatchString("ö", "o")) p(s.FindString("gruss", "Schöne Gruße")) p(s.CommonPrefixString("Lösung", "lost")) s = search.New(language.German) p(s.FindString("gruss", "Schöne Gruße")) // TODO:Output: // true // true // nil // Lös // [8 13] }
Output:
func NewFromWeigher ¶
NewFromWeigher returns a Search given a Weigher.
func (*Search) CommonPrefix ¶
CommonPrefix returns a[:n], where n is the largest value that satisfies s.Match(a[:n], b).
func (*Search) CommonPrefixString ¶
CommonPrefixString returns a[:n], where n is the largest value that satisfies s.Match(a[:n], b).
func (*Search) CompileString ¶
CompileString creates a Pattern from b that can be used to match against text.
func (*Search) Find ¶
Find returns a two-element slice of integers defining the leftmost match in b of pat. A return value of nil indicates no match.
func (*Search) FindAll ¶
FindAll returns a slice of successive matches of pat in b, each represented by a two-element slice of integers. A return value of nil indicates no match.
func (*Search) FindAllString ¶
FindAllString returns a slice of successive matches of pat in str, each represented by a two-element slice of integers. A return value of nil indicates no match.
func (*Search) FindLast ¶
FindLast returns a two-element slice of integers defining the rightmost match in b of pat. A return value of nil indicates no match.
func (*Search) FindLastString ¶
FindLastString returns a two-element slice of integers defining the rightmost match in str of pat. A return value of nil indicates no match.
func (*Search) FindString ¶
FindString returns a two-element slice of integers defining the leftmost match in str of pat. A return value of nil indicates no match.
func (*Search) HasPrefixString ¶
HasPrefixString tests whether the string str begins with prefix.
func (*Search) HasSufixString ¶
HasSuffixString tests whether the string str ends with suffix.
func (*Search) MatchString ¶
MatchString checks whether a and b are equivalent.
func (*Search) SetOptions ¶
SetOptions configures s to the options specified by mask.