Ejemplo n.º 1
0
// Suggest words based on the given word.
// This is a wrapper for enchant_dict_suggest.
// It returns a slice of suggestion strings.
func (e *Enchant) Suggest(word string) (suggestions []string) {
	if len(word) == 0 {
		return suggestions
	}

	cWord := C.CString(word)
	defer C.free(unsafe.Pointer(cWord))

	size := uintptr(len(word))
	s := (*C.ssize_t)(unsafe.Pointer(&size))

	var n int
	nSugg := uintptr(n)
	ns := (*C.size_t)(unsafe.Pointer(&nSugg))

	// get the suggestions; ns will be modified to store the
	// number of suggestions returned
	response := C.enchant_dict_suggest(e.dict, cWord, *s, ns)

	for i := 0; i < int(*ns); i++ {
		ci := C.int(i)
		suggestions = append(suggestions, C.GoString(C.getString(response, ci)))
	}

	return suggestions
}
Ejemplo n.º 2
0
// Suggest performs the spell checking on a word
func (e *Enchant) Suggest(word string) []string {
	if len(word) == 0 {
		return nil
	}

	cWord := C.CString(word)
	defer C.free(unsafe.Pointer(cWord))

	size := uintptr(len(word))
	s := (*C.ssize_t)(unsafe.Pointer(&size))

	var n int
	nSugg := uintptr(n)
	ns := (*C.size_t)(unsafe.Pointer(&nSugg))

	// ns will be modified for how many suggestions there are
	response := C.enchant_dict_suggest(e.dict, cWord, *s, ns)

	var suggestions []string
	for i := 0; i < int(*ns); i++ {
		ci := C.int(i)
		suggestions = append(suggestions, C.GoString(C.getString(response, ci)))
	}

	return suggestions
}