GList * empathy_spell_get_suggestions (const gchar *word) { gint len; GList *l1; GList *suggestion_list = NULL; g_return_val_if_fail (word != NULL, NULL); spell_setup_languages (); len = strlen (word); for (l1 = languages; l1; l1 = l1->next) { SpellLanguage *lang; gchar **suggestions; gsize i, number_of_suggestions; lang = l1->data; suggestions = enchant_dict_suggest (lang->speller, word, len, &number_of_suggestions); for (i = 0; i < number_of_suggestions; i++) { suggestion_list = g_list_append (suggestion_list, g_strdup (suggestions[i])); } if (suggestions) { enchant_dict_free_string_list (lang->speller, suggestions); } } return suggestion_list; }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_NullOutputSuggestionCount) { _suggestions = enchant_dict_suggest(_dict, "helo", -1, NULL); CHECK(_suggestions); CHECK(dictSuggestCalled); }
GSList* suggestions_get(const gchar *lemma) { GSList *suggestions_list = NULL; // check if Enchant broker and English dictionary are initialized if(enchant_broker && enchant_dict) { if(enchant_dict_check(enchant_dict, lemma, -1)) { size_t suggestions_count = 0; gchar **suggestions = enchant_dict_suggest(enchant_dict, lemma, -1, &suggestions_count); for(size_t i = 0; i < suggestions_count; i++) { if(wni_request_nyms(suggestions[i], NULL, (WNIRequestFlags) 0, FALSE)) { suggestions_list = g_slist_append(suggestions_list, g_strdup(suggestions[i])); } } if(suggestions) enchant_dict_free_string_list(enchant_dict, suggestions); } } return suggestions_list; }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_InBrokerPwlSession) { enchant_dict_add(_pwl, "hello", -1); _suggestions = enchant_dict_suggest(_pwl, "helo", -1, NULL); CHECK(_suggestions); CHECK(!dictSuggestCalled); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_StringListFreed) { size_t cSuggs; _suggestions = enchant_dict_suggest(_dict, "helo", -1, &cSuggs); CHECK(dictSuggestCalled); CHECK(providerFreeStringListCalled); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_HasPreviousError_ErrorCleared) { SetErrorOnMockDictionary("something bad happened"); _suggestions = enchant_dict_suggest(_dict, "helo", -1, NULL); CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict)); }
static gint sc_speller_check_word(GeanyDocument *doc, gint line_number, const gchar *word, gint start_pos, gint end_pos) { gsize n_suggs = 0; g_return_val_if_fail(sc_speller_dict != NULL, 0); g_return_val_if_fail(doc != NULL, 0); g_return_val_if_fail(word != NULL, 0); g_return_val_if_fail(start_pos >= 0 && end_pos >= 0, 0); if (! NZV(word)) return 0; /* ignore numbers or words starting with digits */ if (isdigit(*word)) return 0; /* ignore non-text */ if (! sc_speller_is_text(doc, start_pos)) return 0; /* early out if the word is spelled correctly */ if (enchant_dict_check(sc_speller_dict, word, -1) == 0) return 0; editor_indicator_set_on_range(doc->editor, GEANY_INDICATOR_ERROR, start_pos, end_pos); if (sc_info->use_msgwin && line_number != -1) { gsize j; gchar **suggs; GString *str; str = g_string_sized_new(256); suggs = enchant_dict_suggest(sc_speller_dict, word, -1, &n_suggs); if (suggs != NULL) { g_string_append_printf(str, "line %d: %s | ", line_number + 1, word); g_string_append(str, _("Try: ")); /* Now find the misspellings in the line, limit suggestions to a maximum of 15 (for now) */ for (j = 0; j < MIN(n_suggs, 15); j++) { g_string_append(str, suggs[j]); g_string_append_c(str, ' '); } msgwin_msg_add(COLOR_RED, line_number + 1, doc, "%s", str->str); if (suggs != NULL && n_suggs > 0) enchant_dict_free_string_list(sc_speller_dict, suggs); } g_string_free(str, TRUE); } return n_suggs; }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_EmptyWord_NullSuggestions) { _suggestions = enchant_dict_suggest(_dict, "", -1, NULL); CHECK(!_suggestions); CHECK(!dictSuggestCalled); CHECK(!providerFreeStringListCalled); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_WordSize0_NullSuggestions) { _suggestions = enchant_dict_suggest(_dict, "helo", 0, NULL); CHECK(!_suggestions); CHECK(!dictSuggestCalled); CHECK(!providerFreeStringListCalled); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_InvalidUtf8Correction_DoNothing) { _suggestions = enchant_dict_suggest(_dict, "\xa5\xf1\x08", -1, NULL); CHECK(!_suggestions); CHECK(!dictSuggestCalled); CHECK(!providerFreeStringListCalled); }
TEST_FIXTURE(EnchantDictionaryFreeNotImplemented_TestFixture, EnchantDictionaryFreeNotImplemented_Suggestions_FreeNotCalled) { _suggestions = enchant_dict_suggest(_dict, "helo", -1, NULL); CHECK(_suggestions); CHECK(dictSuggestCalled); CHECK(!providerFreeStringListCalled); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_SuggestionExcluded_Null) { suggestBehavior = returnFianceNfc; RemoveWordFromDictionary(Convert(L"fianc\xe9")); // u00e9 = Latin small letter e with acute _suggestions = enchant_dict_suggest(_dict, "fiance", -1, NULL); CHECK(!_suggestions); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_NullSuggestionList_FreeNotCalled) { suggestBehavior = returnNull; size_t cSuggs; _suggestions = enchant_dict_suggest(_dict, "helo", -1, &cSuggs); CHECK(!_suggestions); CHECK_EQUAL(0, cSuggs); CHECK(dictSuggestCalled); CHECK(!providerFreeStringListCalled); }
TEST_FIXTURE(EnchantDictionarySuggestNotImplemented_TestFixture, EnchantDictionarySuggest_WordInDictionaryAndExclude_NotInSuggestions) { ExternalAddWordToExclude("hello"); ExternalAddWordToDictionary("hello"); ReloadTestDictionary(); size_t cSuggestions; _suggestions = enchant_dict_suggest(_dict, "helo", -1, &cSuggestions); CHECK(!_suggestions); CHECK_EQUAL(0, cSuggestions); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_WordNfcInDictionaryNfdInPwl_ReturnsFromDict) { suggestBehavior = returnFianceNfc; ExternalAddWordToDictionary(Convert(L"fiance\x301")); // NFD u0301 = Combining acute accent ReloadTestDictionary(); size_t cSuggestions; _suggestions = enchant_dict_suggest(_dict, "fiance", -1, &cSuggestions); CHECK(_suggestions); CHECK_EQUAL(1, cSuggestions); CHECK_EQUAL(Convert(L"fianc\xe9"), _suggestions[0]); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_LenSpecified) { size_t cSuggestions; _suggestions = enchant_dict_suggest(_dict, "helodisregard me", 4, &cSuggestions); CHECK(_suggestions); CHECK_EQUAL(std::string("helo"), suggestWord); CHECK_EQUAL(4, cSuggestions); std::vector<std::string> suggestions; if(_suggestions != NULL){ suggestions.insert(suggestions.begin(), _suggestions, _suggestions+cSuggestions); } CHECK_ARRAY_EQUAL(GetExpectedSuggestions("helo"), suggestions, std::min((size_t)4,cSuggestions)); }
static void do_mode_a (FILE * out, EnchantDict * dict, GString * word, size_t start_pos, size_t lineCount, gboolean terse_mode) { size_t n_suggs; char ** suggs; if (word->len <= MIN_WORD_LENGTH || enchant_dict_check (dict, word->str, word->len) == 0) { if (!terse_mode) { if (lineCount) fprintf (out, "* %u\n", (unsigned int)lineCount); else fwrite ("*\n", 1, 2, out); } } else { suggs = enchant_dict_suggest (dict, word->str, word->len, &n_suggs); if (!n_suggs || !suggs) { fwrite ("# ", 1, 2, out); if (lineCount) fprintf (out, "%u ", (unsigned int)lineCount); print_utf (out, word->str); fprintf (out, " %u\n", (unsigned int)start_pos); } else { size_t i = 0; fwrite ("& ", 1, 2, out); if (lineCount) fprintf (out, "%u ", (unsigned int)lineCount); print_utf (out, word->str); fprintf (out, " %u %u:", (unsigned int)n_suggs, (unsigned int)start_pos); for (i = 0; i < n_suggs; i++) { fprintf (out, " "); print_utf (out, suggs[i]); if (i != (n_suggs - 1)) fwrite (",", 1, 1, out); else fwrite ("\n", 1, 1, out); } enchant_dict_free_string_list (dict, suggs); } } }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_DuplicateSuggestionsFromPersonal_notIncluded) { size_t cSuggestions; enchant_dict_add(_dict, "aelo", -1); _suggestions = enchant_dict_suggest(_dict, "helo", -1, &cSuggestions); CHECK(_suggestions); CHECK_EQUAL(4, cSuggestions); std::vector<std::string> suggestions; if(_suggestions != NULL){ suggestions.insert(suggestions.begin(), _suggestions, _suggestions+cSuggestions); } CHECK_ARRAY_EQUAL(GetExpectedSuggestions("helo"), suggestions, std::min((size_t)4,cSuggestions)); }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_SuggestionListWithInvalidUtf8_InvalidSuggestionIgnored_FreeCalled) { suggestBehavior = returnFourOneInvalidUtf8; size_t cSuggestions; _suggestions = enchant_dict_suggest(_dict, "helo", -1, &cSuggestions); CHECK(_suggestions); CHECK(dictSuggestCalled); CHECK(providerFreeStringListCalled); CHECK_EQUAL(3, cSuggestions); std::vector<std::string> suggestions; if(_suggestions != NULL){ suggestions.insert(suggestions.begin(), _suggestions, _suggestions+cSuggestions); } CHECK_ARRAY_EQUAL(GetExpectedSuggestions("helo",1), suggestions, std::min((size_t)3,cSuggestions)); }
void EditorClient::getGuessesForWord(const String& word, WTF::Vector<String>& guesses) { GSList* langs = webkit_web_settings_get_spell_languages(m_webView); guesses.clear(); for (; langs; langs = langs->next) { size_t numberOfSuggestions; size_t i; SpellLanguage* lang = static_cast<SpellLanguage*>(langs->data); gchar** suggestions = enchant_dict_suggest(lang->speller, word.utf8().data(), -1, &numberOfSuggestions); for (i = 0; i < numberOfSuggestions && i < 10; i++) guesses.append(String::fromUTF8(suggestions[i])); if (numberOfSuggestions > 0) enchant_dict_free_suggestions(lang->speller, suggestions); } }
void EditorClient::getGuessesForWord(const String& word, WTF::Vector<String>& guesses) { GSList* dicts = webkit_web_settings_get_enchant_dicts(m_webView); guesses.clear(); for (; dicts; dicts = dicts->next) { size_t numberOfSuggestions; size_t i; EnchantDict* dict = static_cast<EnchantDict*>(dicts->data); gchar** suggestions = enchant_dict_suggest(dict, word.utf8().data(), -1, &numberOfSuggestions); for (i = 0; i < numberOfSuggestions && i < 10; i++) guesses.append(String::fromUTF8(suggestions[i])); if (numberOfSuggestions > 0) enchant_dict_free_suggestions(dict, suggestions); } }
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture, EnchantDictionarySuggest_SuggestionsFromPersonal_addedToEnd) { size_t cSuggestions; enchant_dict_add(_dict, "hello", -1); _suggestions = enchant_dict_suggest(_dict, "helo", -1, &cSuggestions); CHECK(_suggestions); CHECK_EQUAL(5, cSuggestions); std::vector<std::string> suggestions; if(_suggestions != NULL){ suggestions.insert(suggestions.begin(), _suggestions, _suggestions+cSuggestions); } std::vector<std::string> expected = GetExpectedSuggestions("helo"); expected.push_back("hello"); CHECK_ARRAY_EQUAL(expected, suggestions, std::min((size_t)5,cSuggestions)); }
GList * empathy_spell_get_suggestions (const gchar *code, const gchar *word) { gint len; GList *suggestion_list = NULL; SpellLanguage *lang; gchar **suggestions; gsize i, number_of_suggestions; g_return_val_if_fail (code != NULL, NULL); g_return_val_if_fail (word != NULL, NULL); spell_setup_languages (); if (!languages) { return NULL; } len = strlen (word); lang = g_hash_table_lookup (languages, code); if (!lang) { return NULL; } suggestions = enchant_dict_suggest (lang->speller, word, len, &number_of_suggestions); for (i = 0; i < number_of_suggestions; i++) { suggestion_list = g_list_append (suggestion_list, g_strdup (suggestions[i])); } if (suggestions) { enchant_dict_free_string_list (lang->speller, suggestions); } return suggestion_list; }
char * weechat_aspell_get_suggestions (struct t_aspell_speller_buffer *speller_buffer, const char *word) { int i, size, max_suggestions, num_suggestions; char *suggestions, *suggestions2; const char *ptr_word; #ifdef USE_ENCHANT char **elements; size_t num_elements; #else const AspellWordList *list; AspellStringEnumeration *elements; #endif max_suggestions = weechat_config_integer (weechat_aspell_config_check_suggestions); if (max_suggestions < 0) return NULL; size = 1; suggestions = malloc (size); if (!suggestions) return NULL; suggestions[0] = '\0'; if (speller_buffer->spellers) { for (i = 0; speller_buffer->spellers[i]; i++) { #ifdef USE_ENCHANT elements = enchant_dict_suggest (speller_buffer->spellers[i], word, -1, &num_elements); if (elements) { if (num_elements > 0) { num_suggestions = 0; while ((ptr_word = elements[num_suggestions]) != NULL) { size += strlen (ptr_word) + ((suggestions[0]) ? 1 : 0); suggestions2 = realloc (suggestions, size); if (!suggestions2) { free (suggestions); enchant_dict_free_string_list (speller_buffer->spellers[i], elements); return NULL; } suggestions = suggestions2; if (suggestions[0]) strcat (suggestions, (num_suggestions == 0) ? "/" : ","); strcat (suggestions, ptr_word); num_suggestions++; if ((max_suggestions >= 0) && (num_suggestions == max_suggestions)) break; } } enchant_dict_free_string_list (speller_buffer->spellers[i], elements); } #else list = aspell_speller_suggest (speller_buffer->spellers[i], word, -1); if (list) { elements = aspell_word_list_elements (list); num_suggestions = 0; while ((ptr_word = aspell_string_enumeration_next (elements)) != NULL) { size += strlen (ptr_word) + ((suggestions[0]) ? 1 : 0); suggestions2 = realloc (suggestions, size); if (!suggestions2) { free (suggestions); delete_aspell_string_enumeration (elements); return NULL; } suggestions = suggestions2; if (suggestions[0]) strcat (suggestions, (num_suggestions == 0) ? "/" : ","); strcat (suggestions, ptr_word); num_suggestions++; if ((max_suggestions >= 0) && (num_suggestions == max_suggestions)) break; } delete_aspell_string_enumeration (elements); } #endif } } /* no suggestions found */ if (!suggestions[0]) { free (suggestions); return NULL; } return suggestions; }
//setup EnchantDictFreeStringList_TestFixture() { _string_list = enchant_dict_suggest (_dict, "foo", -1, NULL); _pwl_string_list = enchant_dict_suggest (_pwl, "foo", -1, NULL); }