Add words even if empty, to prevent undersized lists
This commit is contained in:
parent
8192cf3315
commit
93610858d0
|
@ -22,26 +22,21 @@ func NewList(words []string) List {
|
||||||
for _, w := range words {
|
for _, w := range words {
|
||||||
w = strings.TrimSpace(w)
|
w = strings.TrimSpace(w)
|
||||||
w = strings.ToUpper(w)
|
w = strings.ToUpper(w)
|
||||||
if w != "" {
|
cleaned = append(cleaned, w)
|
||||||
cleaned = append(cleaned, w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return newList(cleaned)
|
return newList(cleaned)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListFromLines(s string) List {
|
func NewListFromLines(s string) List {
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
words := make([]string, 0, strings.Count(s, "\n"))
|
words := make([]string, 0, strings.Count(s, "\n"))
|
||||||
|
|
||||||
scanner := bufio.NewScanner(strings.NewReader(s))
|
scanner := bufio.NewScanner(strings.NewReader(s))
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
word := scanner.Text()
|
word := scanner.Text()
|
||||||
word = strings.TrimSpace(word)
|
word = strings.TrimSpace(word)
|
||||||
word = strings.ToUpper(word)
|
word = strings.ToUpper(word)
|
||||||
|
words = append(words, word)
|
||||||
if word != "" {
|
|
||||||
words = append(words, word)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newList(words)
|
return newList(words)
|
||||||
|
|
Loading…
Reference in New Issue