2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-08-13 22:27:34 +00:00
|
|
|
|
|
|
|
// Package words contains accessors for some nice words.
|
|
|
|
package words
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
_ "embed"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed tails.txt
|
|
|
|
var tailsTxt []byte
|
|
|
|
|
|
|
|
//go:embed scales.txt
|
|
|
|
var scalesTxt []byte
|
|
|
|
|
|
|
|
var (
|
|
|
|
once sync.Once
|
|
|
|
tails, scales []string
|
|
|
|
)
|
|
|
|
|
|
|
|
// Tails returns words about tails.
|
|
|
|
func Tails() []string {
|
|
|
|
once.Do(initWords)
|
|
|
|
return tails
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scales returns words about scales.
|
|
|
|
func Scales() []string {
|
|
|
|
once.Do(initWords)
|
|
|
|
return scales
|
|
|
|
}
|
|
|
|
|
|
|
|
func initWords() {
|
|
|
|
tails = parseWords(tailsTxt)
|
|
|
|
scales = parseWords(scalesTxt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseWords(txt []byte) []string {
|
|
|
|
n := bytes.Count(txt, []byte{'\n'})
|
|
|
|
ret := make([]string, 0, n)
|
|
|
|
for len(txt) > 0 {
|
|
|
|
word := txt
|
|
|
|
i := bytes.IndexByte(txt, '\n')
|
|
|
|
if i != -1 {
|
|
|
|
word, txt = word[:i], txt[i+1:]
|
2021-08-14 02:37:18 +00:00
|
|
|
} else {
|
|
|
|
txt = nil
|
2021-08-13 22:27:34 +00:00
|
|
|
}
|
2021-08-13 22:46:13 +00:00
|
|
|
if word := strings.TrimSpace(string(word)); word != "" && word[0] != '#' {
|
2021-08-13 22:27:34 +00:00
|
|
|
ret = append(ret, word)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|