search

package
v0.0.0-...-2824937 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT, BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package search provides language-sensitive string search functionality.

Index

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

func (p *Pattern) CommonPrefix(b []byte) []byte

CommonPrefix returns b[:n], where n is the largest value that satisfies p.Match(b[:n]).

func (*Pattern) CommonPrefixString

func (p *Pattern) CommonPrefixString(s string) []byte

CommonPrefixString returns s[:n], where n is the largest value that satisfies p.Match(s[:n]).

func (*Pattern) Find

func (p *Pattern) Find(b []byte) []int

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

func (p *Pattern) FindAll(b []byte) [][]int

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

func (p *Pattern) FindAllString(s string) [][]int

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

func (p *Pattern) FindLast(b []byte) []int

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

func (p *Pattern) FindLastString(s string) []int

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

func (p *Pattern) FindString(s string) []int

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) HasPrefix

func (p *Pattern) HasPrefix(b []byte) bool

HasPrefix tests whether the byte slice b begins with p.

func (*Pattern) HasPrefixString

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

HasPrefixString tests whether the string s begins with p.

func (*Pattern) HasSuffix

func (p *Pattern) HasSuffix(b []byte) bool

HasSuffix tests whether the byte slice b ends with p.

func (*Pattern) HasSuffixString

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

HasSuffixString tests whether the string s ends with p.

func (*Pattern) Match

func (p *Pattern) Match(b []byte) bool

Match checks whether b matches p.

func (*Pattern) MatchString

func (p *Pattern) MatchString(b []byte) bool

MatchString checks whether b is equivalent to p.

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

Search provides language-sensitive search functionality.

func New

func New(l language.Tag) *Search

New returns a new Search for the given language.

func NewFromWeigher

func NewFromWeigher(t colltab.Weigher) *Search

NewFromWeigher returns a Search given a Weigher.

func (*Search) CommonPrefix

func (s *Search) CommonPrefix(a, b []byte) []byte

CommonPrefix returns a[:n], where n is the largest value that satisfies s.Match(a[:n], b).

func (*Search) CommonPrefixString

func (s *Search) CommonPrefixString(a, b string) string

CommonPrefixString returns a[:n], where n is the largest value that satisfies s.Match(a[:n], b).

func (*Search) Compile

func (s *Search) Compile(b []byte) *Pattern

Compile creates a Pattern from b that can be used to match against text.

func (*Search) CompileString

func (s *Search) CompileString(b string) *Pattern

CompileString creates a Pattern from b that can be used to match against text.

func (*Search) Find

func (s *Search) Find(b, pat []byte) []int

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

func (s *Search) FindAll(b, pat []byte) [][]int

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

func (s *Search) FindAllString(str, pat string) [][]int

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

func (s *Search) FindLast(b, pat []byte) []int

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

func (s *Search) FindLastString(str, pat string) []int

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

func (s *Search) FindString(str, pat string) []int

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) HasPrefix

func (s *Search) HasPrefix(str, prefix []byte) bool

HasPrefix tests whether the byte slice str begins with prefix.

func (*Search) HasPrefixString

func (s *Search) HasPrefixString(str, prefix string) bool

HasPrefixString tests whether the string str begins with prefix.

func (*Search) HasSufix

func (s *Search) HasSufix(str, suffix []byte) bool

HasSuffix tests whether the byte slice str ends with suffix.

func (*Search) HasSufixString

func (s *Search) HasSufixString(str, suffix string) bool

HasSuffixString tests whether the string str ends with suffix.

func (*Search) Match

func (s *Search) Match(a, b []byte) bool

Match checks whether a and b are equivalent.

func (*Search) MatchString

func (s *Search) MatchString(a, b string) bool

MatchString checks whether a and b are equivalent.

func (*Search) SetOptions

func (s *Search) SetOptions(mask Option) error

SetOptions configures s to the options specified by mask.

Jump to

Keyboard shortcuts

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