github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/exp/locale/search/examples_test.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package search_test 6 7 import ( 8 "fmt" 9 "golang.org/x/exp/locale/search" 10 "golang.org/x/text/language" 11 ) 12 13 func ExampleSearch() { 14 p := func(x ...interface{}) { 15 fmt.Println(x...) 16 } 17 s := search.New(language.English) 18 s.SetOptions(search.IgnoreCase | search.IgnoreDiacritics) 19 20 p(s.MatchString("A", "a")) 21 p(s.MatchString("ö", "o")) 22 p(s.FindString("gruss", "Schöne Gruße")) 23 p(s.CommonPrefixString("Lösung", "lost")) 24 25 s = search.New(language.German) 26 p(s.FindString("gruss", "Schöne Gruße")) 27 28 // TODO:Output: 29 // true 30 // true 31 // nil 32 // Lös 33 // [8 13] 34 } 35 36 func ExamplePattern() { 37 s := search.New(language.German) 38 pat := s.CompileString("gruss") 39 fmt.Println(pat.FindString("Schöne Gruße")) 40 fmt.Println(pat.FindLastString("Schöne Gruße")) 41 // TODO:Output: 42 // [8 13] 43 // [8 13] 44 }