search

package
v0.0.0-...-73df0bb Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2018 License: Apache-2.0, BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package search provides language-specific search and string matching.

Natural language matching can be intricate. For example, Danish will insist "Århus" and "Aarhus" are the same name and Turkish will match I to ı (note the lack of a dot) in a case-insensitive match. This package handles such language-specific details.

Text passed to any of the calls in this message does not need to be normalized.

Index

Constants

View Source
const CLDRVersion = "23"

CLDRVersion is the CLDR version from which the tables in this package are derived.

View Source
const UnicodeVersion = "6.2.0"

UnicodeVersion is the Unicode version from which the tables in this package are derived.

Variables

View Source
var (
	// Supported lists the languages for which search differs from its parent.
	Supported language.Coverage
)

Functions

This section is empty.

Types

type IndexOption

type IndexOption byte

An IndexOption specifies how the Index methods of Pattern or Matcher should match the input.

const (
	// Anchor restricts the search to the start (or end for Backwards) of the
	// text.
	Anchor IndexOption = 1 << iota

	// Backwards starts the search from the end of the text.
	Backwards
)

type Matcher

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

A Matcher implements language-specific string matching.

func New

func New(t language.Tag, opts ...Option) *Matcher

New returns a new Matcher for the given language and options.

func (*Matcher) Compile

func (m *Matcher) Compile(b []byte) *Pattern

Compile compiles and returns a pattern that can be used for faster searching.

func (*Matcher) CompileString

func (m *Matcher) CompileString(s string) *Pattern

CompileString compiles and returns a pattern that can be used for faster searching.

func (*Matcher) Equal

func (m *Matcher) Equal(a, b []byte) bool

Equal reports whether a and b are equivalent.

func (*Matcher) EqualString

func (m *Matcher) EqualString(a, b string) bool

EqualString reports whether a and b are equivalent.

func (*Matcher) Index

func (m *Matcher) Index(b, pat []byte, opts ...IndexOption) (start, end int)

Index reports the start and end position of the first occurrence of pat in b or -1, -1 if pat is not present.

func (*Matcher) IndexString

func (m *Matcher) IndexString(s, pat string, opts ...IndexOption) (start, end int)

IndexString reports the start and end position of the first occurrence of pat in s or -1, -1 if pat is not present.

type Option

type Option func(*Matcher)

An Option configures a Matcher.

var (
	// WholeWord restricts matches to complete words. The default is to match at
	// the character level.
	WholeWord Option = nil

	// Exact requires that two strings are their exact equivalent. For example
	// å would not match aa in Danish. It overrides any of the ignore options.
	Exact Option = nil

	// Loose causes case, diacritics and width to be ignored.
	Loose Option = loose

	// IgnoreCase enables case-insensitive search.
	IgnoreCase Option = ignoreCase

	// IgnoreDiacritics causes diacritics to be ignored ("ö" == "o").
	IgnoreDiacritics Option = ignoreDiacritics

	// IgnoreWidth equates narrow with wide variants.
	IgnoreWidth Option = ignoreWidth
)

type Pattern

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

A Pattern is a compiled search string. It is safe for concurrent use.

func (*Pattern) Index

func (p *Pattern) Index(b []byte, opts ...IndexOption) (start, end int)

Index reports the start and end position of the first occurrence of p in b or -1, -1 if p is not present.

func (*Pattern) IndexString

func (p *Pattern) IndexString(s string, opts ...IndexOption) (start, end int)

IndexString reports the start and end position of the first occurrence of p in s or -1, -1 if p is not present.

Jump to

Keyboard shortcuts

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