File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22package fname
33
44import (
5+ "bufio"
56 _ "embed"
67 "strings"
78)
89
910//go:embed data/adjective
1011var _adjective string
11- var adjective = strings . Split (_adjective , " \n " )
12+ var adjective = split (_adjective )
1213
1314//go:embed data/adverb
1415var _adverb string
15- var adverb = strings . Split (_adverb , " \n " )
16+ var adverb = split (_adverb )
1617
1718//go:embed data/noun
1819var _noun string
19- var noun = strings . Split (_noun , " \n " )
20+ var noun = split (_noun )
2021
2122//go:embed data/verb
2223var _verb string
23- var verb = strings . Split (_verb , " \n " )
24+ var verb = split (_verb )
2425
2526// Dictionary is a collection of words.
2627type Dictionary struct {
@@ -60,3 +61,13 @@ func (d *Dictionary) LengthNoun() int {
6061func (d * Dictionary ) LengthVerb () int {
6162 return len (d .verbs )
6263}
64+
65+ func split (s string ) []string {
66+ scanner := bufio .NewScanner (strings .NewReader (s ))
67+ scanner .Split (bufio .ScanLines )
68+ var lines []string
69+ for scanner .Scan () {
70+ lines = append (lines , scanner .Text ())
71+ }
72+ return lines
73+ }
You can’t perform that action at this time.
0 commit comments