...
1
2
3
4
5 package collate_test
6
7 import (
8 "fmt"
9
10 "golang.org/x/text/collate"
11 "golang.org/x/text/language"
12 )
13
14 type book struct {
15 title string
16 }
17
18 type bookcase struct {
19 books []book
20 }
21
22 func (bc bookcase) Len() int {
23 return len(bc.books)
24 }
25
26 func (bc bookcase) Swap(i, j int) {
27 temp := bc.books[i]
28 bc.books[i] = bc.books[j]
29 bc.books[j] = temp
30 }
31
32 func (bc bookcase) Bytes(i int) []byte {
33
34 return []byte(bc.books[i].title)
35 }
36
37 func ExampleCollator_Sort() {
38 bc := bookcase{
39 books: []book{
40 {title: "If Cats Disappeared from the World"},
41 {title: "The Guest Cat"},
42 {title: "Catwings"},
43 },
44 }
45
46 cc := collate.New(language.English)
47 cc.Sort(bc)
48
49 for _, b := range bc.books {
50 fmt.Println(b.title)
51 }
52
53
54
55
56 }
57
View as plain text