TEST_FIXTURE(EnchantDictFreeStringList_TestFixture,
             EnchantDictFreeStringListOnPwl)
{
    testResults_;
    enchant_dict_free_string_list(_pwl, _string_list);
    _string_list = NULL;
}
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;
}
Exemple #3
0
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;
}
Exemple #4
0
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(EnchantDictFreeStringList_TestFixture, 
             EnchantDictFreeStringList_HasPreviousError_ErrorCleared)
{
  SetErrorOnMockDictionary("something bad happened");

  enchant_dict_free_string_list(_dict, _string_list);
  _string_list = NULL;

  CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict));
}
Exemple #6
0
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);
		}
	}
}
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;
}
Exemple #9
0
void sc_speller_dict_free_string_list(gchar **tmp_suggs)
{
	g_return_if_fail(sc_speller_dict != NULL);

	enchant_dict_free_string_list(sc_speller_dict, tmp_suggs);
}
TEST_FIXTURE(EnchantDictFreeStringList_TestFixture,
             EnchantDictFreeStringList_NullStringList_DoNothing)
{
    testResults_;
    enchant_dict_free_string_list(_dict, NULL);
}