gboolean sc_speller_dict_check(const gchar *word) { g_return_val_if_fail(sc_speller_dict != NULL, FALSE); g_return_val_if_fail(word != NULL, FALSE); return enchant_dict_check(sc_speller_dict, word, -1); }
int weechat_aspell_check_word (struct t_aspell_speller_buffer *speller_buffer, const char *word) { int i; /* word too small? then do not check word */ if ((weechat_config_integer (weechat_aspell_config_check_word_min_length) > 0) && ((int)strlen (word) < weechat_config_integer (weechat_aspell_config_check_word_min_length))) return 1; /* word is a number? then do not check word */ if (weechat_aspell_string_is_simili_number (word)) return 1; /* check word with all spellers (order is important) */ if (speller_buffer->spellers) { for (i = 0; speller_buffer->spellers[i]; i++) { #ifdef USE_ENCHANT if (enchant_dict_check (speller_buffer->spellers[i], word, strlen (word)) == 0) #else if (aspell_speller_check (speller_buffer->spellers[i], word, -1) == 1) #endif /* USE_ENCHANT */ return 1; } } /* misspelled word! */ return 0; }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordExistsInSession_0_DoesNotCallProvider) { enchant_dict_add_to_session(_dict, "session", -1); CHECK_EQUAL(0, enchant_dict_check(_dict, "session", -1)); CHECK(!dictCheckCalled); }
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; }
void EditorClient::checkSpellingOfString(const UChar* text, int length, int* misspellingLocation, int* misspellingLength) { GSList* dicts = webkit_web_settings_get_enchant_dicts(m_webView); if (!dicts) return; gchar* ctext = g_utf16_to_utf8(const_cast<gunichar2*>(text), length, 0, 0, 0); int utflen = g_utf8_strlen(ctext, -1); PangoLanguage* language = pango_language_get_default(); PangoLogAttr* attrs = g_new(PangoLogAttr, utflen+1); // pango_get_log_attrs uses an aditional position at the end of the text. pango_get_log_attrs(ctext, -1, -1, language, attrs, utflen+1); for (int i = 0; i < length+1; i++) { // We go through each character until we find an is_word_start, // then we get into an inner loop to find the is_word_end corresponding // to it. if (attrs[i].is_word_start) { int start = i; int end = i; int wordLength; while (attrs[end].is_word_end < 1) end++; wordLength = end - start; // Set the iterator to be at the current word end, so we don't // check characters twice. i = end; for (; dicts; dicts = dicts->next) { EnchantDict* dict = static_cast<EnchantDict*>(dicts->data); gchar* cstart = g_utf8_offset_to_pointer(ctext, start); gint bytes = static_cast<gint>(g_utf8_offset_to_pointer(ctext, end) - cstart); gchar* word = g_new0(gchar, bytes+1); int result; g_utf8_strncpy(word, cstart, end - start); result = enchant_dict_check(dict, word, -1); g_free(word); if (result) { *misspellingLocation = start; *misspellingLength = wordLength; } else { // Stop checking, this word is ok in at least one dict. *misspellingLocation = -1; *misspellingLength = 0; break; } } } } g_free(attrs); g_free(ctext); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_HasPreviousError_ErrorCleared) { SetErrorOnMockDictionary("something bad happened"); enchant_dict_check(_dict, "hello", -1); CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict)); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordExistsInPersonal_0_DoesNotCallProvider) { enchant_dict_add(_dict, "personal", -1); CHECK_EQUAL(0, enchant_dict_check(_dict, "personal", -1)); CHECK(!dictCheckCalled); }
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(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordInDictionaryAndExclude_1) { ExternalAddWordToExclude("hello"); ExternalAddWordToDictionary("hello"); ReloadTestDictionary(); CHECK_EQUAL(1, enchant_dict_check(_dict, "hello", -1)); }
static void do_mode_l (FILE * out, EnchantDict * dict, GString * word, size_t lineCount) { if (enchant_dict_check (dict, word->str, word->len) != 0) { if (lineCount) fprintf (out, "%u ", (unsigned int)lineCount); print_utf (out, word->str); fwrite ("\n", 1, 1, out); } }
gboolean cong_is_word_misspelt (const gchar* string, const CongWord* word) { if(!dict) { create_dict(); } return enchant_dict_check(dict, string + word->start_byte_offset, word->length_in_bytes); }
int weechat_aspell_check_word (struct t_gui_buffer *buffer, struct t_aspell_speller_buffer *speller_buffer, const char *word) { const char *buffer_type, *buffer_nick, *buffer_channel; int i; /* word too small? then do not check word */ if ((weechat_config_integer (weechat_aspell_config_check_word_min_length) > 0) && ((int)strlen (word) < weechat_config_integer (weechat_aspell_config_check_word_min_length))) return 1; /* word is a number? then do not check word */ if (weechat_aspell_string_is_simili_number (word)) return 1; /* word is a nick of nicklist on this buffer? then do not check word */ if (weechat_nicklist_search_nick (buffer, NULL, word)) return 1; /* for "private" buffers, ignore self and remote nicks */ buffer_type = weechat_buffer_get_string (buffer, "localvar_type"); if (buffer_type && (strcmp (buffer_type, "private") == 0)) { /* check self nick */ buffer_nick = weechat_buffer_get_string (buffer, "localvar_nick"); if (buffer_nick && (weechat_strcasecmp (buffer_nick, word) == 0)) return 1; /* check remote nick */ buffer_channel = weechat_buffer_get_string (buffer, "localvar_channel"); if (buffer_channel && (weechat_strcasecmp (buffer_channel, word) == 0)) return 1; } /* check word with all spellers for this buffer (order is important) */ if (speller_buffer->spellers) { for (i = 0; speller_buffer->spellers[i]; i++) { #ifdef USE_ENCHANT if (enchant_dict_check (speller_buffer->spellers[i], word, strlen (word)) == 0) #else if (aspell_speller_check (speller_buffer->spellers[i], word, -1) == 1) #endif return 1; } } /* misspelled word! */ return 0; }
/* @doc: spellchecker.check @type: function @title: $spellchecker.check @short: Check a single work for spelling mistakes. @syntax: <bool> $spellchecker.check(<word:string>) @description: This function returns true if the word is spelled correctly. */ static bool spellchecker_kvs_check(KviKvsModuleFunctionCall* c) { QString szWord; KVSM_PARAMETERS_BEGIN(c) KVSM_PARAMETER("word", KVS_PT_STRING, 0, szWord) KVSM_PARAMETERS_END(c) QByteArray utf8 = szWord.toUtf8(); bool bResult = g_pEnchantDicts->isEmpty(); KviPointerListIterator<EnchantDict> it(*g_pEnchantDicts); for (bool b = it.moveFirst(); b; b = it.moveNext()) bResult |= enchant_dict_check(*it, utf8.data(), utf8.size()) == 0; c->returnValue()->setBoolean(bResult); return true; }
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); } } }
gboolean empathy_spell_check (const gchar *word) { gint enchant_result = 1; const gchar *p; gboolean digit; gunichar c; gint len; GList *l; g_return_val_if_fail (word != NULL, FALSE); spell_setup_languages (); if (!languages) { DEBUG ("No languages to check against"); return TRUE; } /* Ignore certain cases like numbers, etc. */ for (p = word, digit = TRUE; *p && digit; p = g_utf8_next_char (p)) { c = g_utf8_get_char (p); digit = g_unichar_isdigit (c); } if (digit) { /* We don't spell check digits. */ DEBUG ("Not spell checking word:'%s', it is all digits", word); return TRUE; } len = strlen (word); for (l = languages; l; l = l->next) { SpellLanguage *lang; lang = l->data; enchant_result = enchant_dict_check (lang->speller, word, len); if (enchant_result == 0) { break; } } return (enchant_result == 0); }
gboolean empathy_spell_check (const gchar *word) { gint enchant_result = 1; const gchar *p; gboolean digit; gunichar c; gint len; GHashTableIter iter; SpellLanguage *lang; g_return_val_if_fail (word != NULL, FALSE); spell_setup_languages (); if (!languages) { return TRUE; } /* Ignore certain cases like numbers, etc. */ for (p = word, digit = TRUE; *p && digit; p = g_utf8_next_char (p)) { c = g_utf8_get_char (p); digit = g_unichar_isdigit (c); } if (digit) { /* We don't spell check digits. */ DEBUG ("Not spell checking word:'%s', it is all digits", word); return TRUE; } len = strlen (word); g_hash_table_iter_init (&iter, languages); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &lang)) { enchant_result = enchant_dict_check (lang->speller, word, len); if (enchant_result == 0) { break; } } return (enchant_result == 0); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordDoesExists_InBrokerPwlSession_0) { enchant_dict_add_to_session(_pwl, "session", -1); CHECK_EQUAL(0, enchant_dict_check(_pwl, "session", -1)); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordDoesExists_InBrokerPwl_0) { enchant_dict_add(_pwl, "personal", -1); CHECK_EQUAL(0, enchant_dict_check(_pwl, "personal", -1)); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordDoesNotExist_InBrokerPwl_1) { CHECK_EQUAL(1, enchant_dict_check(_pwl, "session", -1)); }
///////////////////////////////////////////////////////////////////////////// // Test Error Conditions TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_NullDictionary_Negative1) { CHECK_EQUAL(-1, enchant_dict_check(NULL, "helo", -1)); CHECK(!dictCheckCalled); }
TEST_FIXTURE(EnchantDictionaryCheckNotImplemented_TestFixture, EnchantDictionaryCheckNotImplemented_InBrokerPwl_1) { CHECK_EQUAL(1, enchant_dict_check(_pwl, "hello", -1)); CHECK(!dictCheckCalled); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordSize0_Negative1) { CHECK_EQUAL(-1, enchant_dict_check(_dict, "helo", 0)); CHECK(!dictCheckCalled); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_InvalidUtf8Word_Negative1) { CHECK_EQUAL(-1, enchant_dict_check(_dict, "\xa5\xf1\x08", -1)); CHECK(!dictCheckCalled); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordExists_LenSpecified_0) { CHECK_EQUAL(0, enchant_dict_check(_dict, "hellodisregard me", 5)); CHECK(dictCheckCalled); }
///////////////////////////////////////////////////////////////////////////// // Test Normal Operation TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordExists_LenComputed_0) { CHECK_EQUAL(0, enchant_dict_check(_dict, "hello", -1)); CHECK(dictCheckCalled); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordDoesNotExist_LenSpecified_1) { CHECK_EQUAL(1, enchant_dict_check(_dict, "helodisregard me", 4)); CHECK(dictCheckCalled); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_EmptyWord_Negative1) { CHECK_EQUAL(-1, enchant_dict_check(_dict, "", -1)); CHECK(!dictCheckCalled); }
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture, EnchantDictionaryCheck_WordDoesNotExist_LenComputed_1) { CHECK_EQUAL(1, enchant_dict_check(_dict, "helo", -1)); CHECK(dictCheckCalled); }
TEST_FIXTURE(EnchantDictionaryCheckNotImplemented_TestFixture, EnchantDictionaryCheckNotImplemented_Negative1) { CHECK_EQUAL(-1, enchant_dict_check(_dict, "hello", -1)); CHECK(!dictCheckCalled); }