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; }
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); }
void empathy_spell_add_to_dictionary (const gchar *code, const gchar *word) { SpellLanguage *lang; g_return_if_fail (code != NULL); g_return_if_fail (word != NULL); spell_setup_languages (); if (languages == NULL) return; lang = g_hash_table_lookup (languages, code); if (lang == NULL) return; enchant_dict_add_to_pwl (lang->speller, word, strlen (word)); }
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); }
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; }
GList * empathy_spell_get_enabled_language_codes (void) { spell_setup_languages (); return g_hash_table_get_keys (languages); }