CheckWord checks a single word and returns suggestions if word is unknown. bool is true if word is in the dictionary, false otherwise.
(word string)
| 143 | // CheckWord checks a single word and returns suggestions if word is unknown. |
| 144 | // bool is true if word is in the dictionary, false otherwise. |
| 145 | func (sp *SpellData) CheckWord(word string) ([]string, bool) { |
| 146 | if sp.model == nil { |
| 147 | log.Println("spell.CheckWord: programmer error -- Spelling not initialized!") |
| 148 | return nil, false |
| 149 | } |
| 150 | w := lexer.FirstWordApostrophe(word) // only lookup words |
| 151 | orig := w |
| 152 | w = strings.ToLower(w) |
| 153 | |
| 154 | sp.mu.RLock() |
| 155 | defer sp.mu.RUnlock() |
| 156 | if sp.model.Ignore.Exists(w) { |
| 157 | return nil, true |
| 158 | } |
| 159 | suggests := sp.model.Suggestions(w, 10) |
| 160 | if suggests == nil { // no sug and not known |
| 161 | return nil, false |
| 162 | } |
| 163 | if len(suggests) == 1 && suggests[0] == w { |
| 164 | return nil, true |
| 165 | } |
| 166 | for i, s := range suggests { |
| 167 | suggests[i] = lexer.MatchCase(orig, s) |
| 168 | } |
| 169 | return suggests, false |
| 170 | } |
| 171 | |
| 172 | // AddWord adds given word to the User dictionary |
| 173 | func (sp *SpellData) AddWord(word string) { |
no test coverage detected