func commandLine(words wordmap.WordsMap) { fmt.Println("Type q to quit.") for { fmt.Print("Enter letters: ") var letters string if _, err := fmt.Scanln(&letters); err != nil { if err != io.EOF { log.Fatalln(err) } return } if letters == "q" { return } letters = strings.TrimSpace(letters) for word := range words.GetWords(letters) { fmt.Println(word) } } }
func CreateWordsMap(source string) wordmap.WordsMap { words := wordmap.WordsMap{} reader := getWords(source) defer reader.Close() scanner := bufio.NewScanner(reader) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) if len(line) > 0 { words.AddWord(line) } } return words }