...
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 func ExampleNew() {
15 letters := []string{"ä", "å", "ö", "o", "a"}
16
17 ec := collate.New(language.English)
18 ec.SortStrings(letters)
19 fmt.Printf("English Sorting: %v\n", letters)
20
21 sc := collate.New(language.Swedish)
22 sc.SortStrings(letters)
23 fmt.Printf("Swedish Sorting: %v\n", letters)
24
25 numbers := []string{"0", "11", "01", "2", "3", "23"}
26
27 ec.SortStrings(numbers)
28 fmt.Printf("Alphabetic Sorting: %v\n", numbers)
29
30 nc := collate.New(language.English, collate.Numeric)
31 nc.SortStrings(numbers)
32 fmt.Printf("Numeric Sorting: %v\n", numbers)
33
34
35
36
37
38 }
39
40 func ExampleCollator_SortStrings() {
41 c := collate.New(language.English)
42 words := []string{"meow", "woof", "bark", "moo"}
43 c.SortStrings(words)
44 fmt.Println(words)
45
46
47 }
48
49 func ExampleCollator_CompareString() {
50 c := collate.New(language.English)
51 r := c.CompareString("meow", "woof")
52 fmt.Println(r)
53
54 r = c.CompareString("woof", "meow")
55 fmt.Println(r)
56
57 r = c.CompareString("meow", "meow")
58 fmt.Println(r)
59
60
61
62
63 }
64
65 func ExampleCollator_Compare() {
66 c := collate.New(language.English)
67 r := c.Compare([]byte("meow"), []byte("woof"))
68 fmt.Println(r)
69
70 r = c.Compare([]byte("woof"), []byte("meow"))
71 fmt.Println(r)
72
73 r = c.Compare([]byte("meow"), []byte("meow"))
74 fmt.Println(r)
75
76
77
78
79 }
80
View as plain text