-
Notifications
You must be signed in to change notification settings - Fork 1
/
words.go
64 lines (54 loc) · 1.07 KB
/
words.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"bufio"
"io"
"sort"
"strings"
)
type WordList struct {
Name string
Author string
License string
Origin string
Index IndexStringer
Words string
}
var internalLists = map[string]*WordList{}
func linesFromInternalList(list string) []string {
r := internalListReader(list)
if r == nil {
return nil
}
defer r.Close()
return readerToLines(r)
}
func readerToLines(r io.Reader) []string {
scanner := bufio.NewScanner(r)
scanner.Split(bufio.ScanLines)
lines := make([]string, 0)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines
}
func internalListReader(name string) io.ReadCloser {
list, exists := internalLists[name]
if !exists {
return nil
}
return listReaderFromString(list.Words)
}
func listReaderFromString(list string) io.ReadCloser {
r := strings.NewReader(strings.TrimSpace(list))
return io.NopCloser(r)
}
func internalListNames() []string {
names := make([]string, len(internalLists))
i := 0
for name := range internalLists {
names[i] = name
i++
}
sort.Strings(names)
return names
}