MCPcopy Create free account
hub / github.com/cogentcore/core / CheckWord

Method CheckWord

spell/spell.go:145–170  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
145func (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
173func (sp *SpellData) AddWord(word string) {

Callers 2

CheckLexLineFunction · 0.80
checkWordMethod · 0.80

Calls 5

FirstWordApostropheFunction · 0.92
MatchCaseFunction · 0.92
PrintlnMethod · 0.80
ExistsMethod · 0.80
SuggestionsMethod · 0.80

Tested by

no test coverage detected