Commit 5eb218e0 authored by Sébastien Wilmet's avatar Sébastien Wilmet

spell: remove unused len parameters

The string length parameters complicate a little the code everywhere.
But it is used nowhere. So simplify that.
parent 19a6a923
......@@ -69,7 +69,7 @@ check_word (GeditAutomaticSpellChecker *spell,
word = gtk_text_buffer_get_text (spell->buffer, start, end, FALSE);
if (!gedit_spell_checker_check_word (spell->spell_checker, word, -1))
if (!gedit_spell_checker_check_word (spell->spell_checker, word))
{
gtk_text_buffer_apply_tag (spell->buffer,
spell->tag_highlight,
......@@ -299,7 +299,7 @@ add_to_dictionary_cb (GtkWidget *menu_item,
word = gtk_text_buffer_get_text (spell->buffer, &start, &end, FALSE);
gedit_spell_checker_add_word_to_personal (spell->spell_checker, word, -1);
gedit_spell_checker_add_word_to_personal (spell->spell_checker, word);
g_free (word);
}
......@@ -319,7 +319,7 @@ ignore_all_cb (GtkWidget *menu_item,
word = gtk_text_buffer_get_text (spell->buffer, &start, &end, FALSE);
gedit_spell_checker_add_word_to_session (spell->spell_checker, word, -1);
gedit_spell_checker_add_word_to_session (spell->spell_checker, word);
g_free (word);
}
......@@ -350,9 +350,7 @@ replace_word_cb (GtkWidget *menu_item,
gtk_text_buffer_end_user_action (spell->buffer);
gedit_spell_checker_set_correction (spell->spell_checker,
old_word, strlen (old_word),
new_word, strlen (new_word));
gedit_spell_checker_set_correction (spell->spell_checker, old_word, new_word);
g_free (old_word);
}
......@@ -367,7 +365,7 @@ get_suggestion_menu (GeditAutomaticSpellChecker *spell,
top_menu = gtk_menu_new ();
suggestions = gedit_spell_checker_get_suggestions (spell->spell_checker, word, -1);
suggestions = gedit_spell_checker_get_suggestions (spell->spell_checker, word);
if (suggestions == NULL)
{
......@@ -534,17 +532,10 @@ remove_tag_to_word (GeditAutomaticSpellChecker *spell,
static void
add_word_cb (GeditSpellChecker *checker,
const gchar *_word,
gint len,
const gchar *word,
GeditAutomaticSpellChecker *spell)
{
gchar *word;
word = len < 0 ? g_strdup (_word) : g_strndup (_word, len);
remove_tag_to_word (spell, word);
g_free (word);
}
static void
......
......@@ -367,7 +367,7 @@ gedit_spell_checker_dialog_set_spell_checker (GeditSpellCheckerDialog *dlg, Gedi
gedit_spell_checker_language_to_string (language));
if (dlg->misspelled_word != NULL)
gedit_spell_checker_dialog_set_misspelled_word (dlg, dlg->misspelled_word, -1);
gedit_spell_checker_dialog_set_misspelled_word (dlg, dlg->misspelled_word);
else
gtk_list_store_clear (GTK_LIST_STORE (dlg->suggestions_list_model));
......@@ -376,8 +376,7 @@ gedit_spell_checker_dialog_set_spell_checker (GeditSpellCheckerDialog *dlg, Gedi
void
gedit_spell_checker_dialog_set_misspelled_word (GeditSpellCheckerDialog *dlg,
const gchar *word,
gint len)
const gchar *word)
{
gchar *tmp;
GSList *sug;
......@@ -386,7 +385,7 @@ gedit_spell_checker_dialog_set_misspelled_word (GeditSpellCheckerDialog *dlg,
g_return_if_fail (word != NULL);
g_return_if_fail (dlg->spell_checker != NULL);
g_return_if_fail (!gedit_spell_checker_check_word (dlg->spell_checker, word, -1));
g_return_if_fail (!gedit_spell_checker_check_word (dlg->spell_checker, word));
g_free (dlg->misspelled_word);
dlg->misspelled_word = g_strdup (word);
......@@ -396,8 +395,7 @@ gedit_spell_checker_dialog_set_misspelled_word (GeditSpellCheckerDialog *dlg,
g_free (tmp);
sug = gedit_spell_checker_get_suggestions (dlg->spell_checker,
dlg->misspelled_word,
-1);
dlg->misspelled_word);
update_suggestions_list_model (dlg, sug);
......@@ -509,15 +507,13 @@ static void
check_word_button_clicked_handler (GtkButton *button, GeditSpellCheckerDialog *dlg)
{
const gchar *word;
gssize len;
g_return_if_fail (GEDIT_IS_SPELL_CHECKER_DIALOG (dlg));
word = gtk_entry_get_text (GTK_ENTRY (dlg->word_entry));
len = strlen (word);
g_return_if_fail (len > 0);
g_return_if_fail (gtk_entry_get_text_length (GTK_ENTRY (dlg->word_entry)) > 0);
if (gedit_spell_checker_check_word (dlg->spell_checker, word, len))
if (gedit_spell_checker_check_word (dlg->spell_checker, word))
{
GtkListStore *store;
GtkTreeIter iter;
......@@ -537,9 +533,7 @@ check_word_button_clicked_handler (GtkButton *button, GeditSpellCheckerDialog *d
{
GSList *sug;
sug = gedit_spell_checker_get_suggestions (dlg->spell_checker,
word,
len);
sug = gedit_spell_checker_get_suggestions (dlg->spell_checker, word);
update_suggestions_list_model (dlg, sug);
......@@ -556,8 +550,7 @@ add_word_button_clicked_handler (GtkButton *button, GeditSpellCheckerDialog *dlg
g_return_if_fail (dlg->misspelled_word != NULL);
gedit_spell_checker_add_word_to_personal (dlg->spell_checker,
dlg->misspelled_word,
-1);
dlg->misspelled_word);
word = g_strdup (dlg->misspelled_word);
......@@ -590,8 +583,7 @@ ignore_all_button_clicked_handler (GtkButton *button, GeditSpellCheckerDialog *d
g_return_if_fail (dlg->misspelled_word != NULL);
gedit_spell_checker_add_word_to_session (dlg->spell_checker,
dlg->misspelled_word,
-1);
dlg->misspelled_word);
word = g_strdup (dlg->misspelled_word);
......@@ -614,8 +606,8 @@ change_button_clicked_handler (GtkButton *button, GeditSpellCheckerDialog *dlg)
g_return_if_fail (*change != '\0');
gedit_spell_checker_set_correction (dlg->spell_checker,
dlg->misspelled_word, -1,
change, -1);
dlg->misspelled_word,
change);
word = g_strdup (dlg->misspelled_word);
......@@ -651,8 +643,8 @@ change_all_button_clicked_handler (GtkButton *button, GeditSpellCheckerDialog *d
g_return_if_fail (*change != '\0');
gedit_spell_checker_set_correction (dlg->spell_checker,
dlg->misspelled_word, -1,
change, -1);
dlg->misspelled_word,
change);
word = g_strdup (dlg->misspelled_word);
......
......@@ -73,8 +73,7 @@ void gedit_spell_checker_dialog_set_spell_checker (GeditSpellCheckerDialog *dl
GeditSpellChecker *spell);
void gedit_spell_checker_dialog_set_misspelled_word (GeditSpellCheckerDialog *dlg,
const gchar *word,
gint len);
const gchar *word);
void gedit_spell_checker_dialog_set_completed (GeditSpellCheckerDialog *dlg);
......
......@@ -145,9 +145,8 @@ gedit_spell_checker_class_init (GeditSpellCheckerClass * klass)
G_STRUCT_OFFSET (GeditSpellCheckerClass, add_word_to_personal),
NULL, NULL, NULL,
G_TYPE_NONE,
2,
G_TYPE_STRING,
G_TYPE_INT);
1,
G_TYPE_STRING);
signals[ADD_WORD_TO_SESSION] =
g_signal_new ("add_word_to_session",
......@@ -156,9 +155,8 @@ gedit_spell_checker_class_init (GeditSpellCheckerClass * klass)
G_STRUCT_OFFSET (GeditSpellCheckerClass, add_word_to_session),
NULL, NULL, NULL,
G_TYPE_NONE,
2,
G_TYPE_STRING,
G_TYPE_INT);
1,
G_TYPE_STRING);
signals[SET_LANGUAGE] =
g_signal_new ("set_language",
......@@ -327,8 +325,7 @@ gedit_spell_checker_get_language (GeditSpellChecker *spell)
gboolean
gedit_spell_checker_check_word (GeditSpellChecker *spell,
const gchar *word,
gssize len)
const gchar *word)
{
gint enchant_result;
gboolean res = FALSE;
......@@ -339,17 +336,14 @@ gedit_spell_checker_check_word (GeditSpellChecker *spell,
if (!lazy_init (spell, spell->active_lang))
return FALSE;
if (len < 0)
len = strlen (word);
if (strcmp (word, "gedit") == 0)
return TRUE;
if (gedit_spell_utils_is_digit (word, len))
if (gedit_spell_utils_is_digit (word))
return TRUE;
g_return_val_if_fail (spell->dict != NULL, FALSE);
enchant_result = enchant_dict_check (spell->dict, word, len);
enchant_result = enchant_dict_check (spell->dict, word, strlen (word));
switch (enchant_result)
{
......@@ -380,8 +374,7 @@ gedit_spell_checker_check_word (GeditSpellChecker *spell,
/* return NULL on error or if no suggestions are found */
GSList *
gedit_spell_checker_get_suggestions (GeditSpellChecker *spell,
const gchar *word,
gssize len)
const gchar *word)
{
gchar **suggestions;
size_t n_suggestions = 0;
......@@ -396,10 +389,7 @@ gedit_spell_checker_get_suggestions (GeditSpellChecker *spell,
g_return_val_if_fail (spell->dict != NULL, NULL);
if (len < 0)
len = strlen (word);
suggestions = enchant_dict_suggest (spell->dict, word, len, &n_suggestions);
suggestions = enchant_dict_suggest (spell->dict, word, strlen (word), &n_suggestions);
if (n_suggestions == 0)
return NULL;
......@@ -422,8 +412,7 @@ gedit_spell_checker_get_suggestions (GeditSpellChecker *spell,
gboolean
gedit_spell_checker_add_word_to_personal (GeditSpellChecker *spell,
const gchar *word,
gssize len)
const gchar *word)
{
g_return_val_if_fail (GEDIT_IS_SPELL_CHECKER (spell), FALSE);
g_return_val_if_fail (word != NULL, FALSE);
......@@ -433,20 +422,16 @@ gedit_spell_checker_add_word_to_personal (GeditSpellChecker *spell,
g_return_val_if_fail (spell->dict != NULL, FALSE);
if (len < 0)
len = strlen (word);
enchant_dict_add_to_pwl (spell->dict, word, strlen (word));
enchant_dict_add_to_pwl (spell->dict, word, len);
g_signal_emit (G_OBJECT (spell), signals[ADD_WORD_TO_PERSONAL], 0, word, len);
g_signal_emit (G_OBJECT (spell), signals[ADD_WORD_TO_PERSONAL], 0, word);
return TRUE;
}
gboolean
gedit_spell_checker_add_word_to_session (GeditSpellChecker *spell,
const gchar *word,
gssize len)
const gchar *word)
{
g_return_val_if_fail (GEDIT_IS_SPELL_CHECKER (spell), FALSE);
g_return_val_if_fail (word != NULL, FALSE);
......@@ -456,12 +441,9 @@ gedit_spell_checker_add_word_to_session (GeditSpellChecker *spell,
g_return_val_if_fail (spell->dict != NULL, FALSE);
if (len < 0)
len = strlen (word);
enchant_dict_add_to_session (spell->dict, word, len);
enchant_dict_add_to_session (spell->dict, word, strlen (word));
g_signal_emit (G_OBJECT (spell), signals[ADD_WORD_TO_SESSION], 0, word, len);
g_signal_emit (G_OBJECT (spell), signals[ADD_WORD_TO_SESSION], 0, word);
return TRUE;
}
......@@ -493,9 +475,7 @@ gedit_spell_checker_clear_session (GeditSpellChecker *spell)
gboolean
gedit_spell_checker_set_correction (GeditSpellChecker *spell,
const gchar *word,
gssize w_len,
const gchar *replacement,
gssize r_len)
const gchar *replacement)
{
g_return_val_if_fail (GEDIT_IS_SPELL_CHECKER (spell), FALSE);
g_return_val_if_fail (word != NULL, FALSE);
......@@ -506,17 +486,11 @@ gedit_spell_checker_set_correction (GeditSpellChecker *spell,
g_return_val_if_fail (spell->dict != NULL, FALSE);
if (w_len < 0)
w_len = strlen (word);
if (r_len < 0)
r_len = strlen (replacement);
enchant_dict_store_replacement (spell->dict,
word,
w_len,
strlen (word),
replacement,
r_len);
strlen (replacement));
return TRUE;
}
......
......@@ -44,12 +44,10 @@ struct _GeditSpellCheckerClass
/* Signals */
void (*add_word_to_personal) (GeditSpellChecker *spell,
const gchar *word,
gint len);
const gchar *word);
void (*add_word_to_session) (GeditSpellChecker *spell,
const gchar *word,
gint len);
const gchar *word);
void (*set_language) (GeditSpellChecker *spell,
const GeditSpellCheckerLanguage *lang);
......@@ -67,30 +65,24 @@ const GeditSpellCheckerLanguage
*gedit_spell_checker_get_language (GeditSpellChecker *spell);
gboolean gedit_spell_checker_check_word (GeditSpellChecker *spell,
const gchar *word,
gssize len);
const gchar *word);
GSList *gedit_spell_checker_get_suggestions (GeditSpellChecker *spell,
const gchar *word,
gssize len);
const gchar *word);
gboolean gedit_spell_checker_add_word_to_personal
(GeditSpellChecker *spell,
const gchar *word,
gssize len);
const gchar *word);
gboolean gedit_spell_checker_add_word_to_session
(GeditSpellChecker *spell,
const gchar *word,
gssize len);
const gchar *word);
gboolean gedit_spell_checker_clear_session (GeditSpellChecker *spell);
gboolean gedit_spell_checker_set_correction (GeditSpellChecker *spell,
const gchar *word,
gssize w_len,
const gchar *replacement,
gssize r_len);
const gchar *replacement);
G_END_DECLS
......
......@@ -574,7 +574,7 @@ get_next_misspelled_word (GeditView *view,
gedit_debug_message (DEBUG_PLUGINS, "Word to check: %s", word);
while (gedit_spell_checker_check_word (checker, word, -1))
while (gedit_spell_checker_check_word (checker, word))
{
g_free (word);
......@@ -659,9 +659,7 @@ ignore_cb (GeditSpellCheckerDialog *dlg,
select_misspelled_word (view, word_start_offset, word_end_offset);
gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg),
word,
-1);
gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg), word);
g_free (word);
}
......@@ -948,9 +946,7 @@ spell_cb (GSimpleAction *action,
g_signal_connect (dlg, "add_word_to_personal", G_CALLBACK (add_word_cb), view);
gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg),
word,
-1);
gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg), word);
g_free (word);
......
......@@ -23,21 +23,15 @@
#include <gtksourceview/gtksource.h>
gboolean
gedit_spell_utils_is_digit (const gchar *text,
gssize length)
gedit_spell_utils_is_digit (const gchar *text)
{
const gchar *p;
const gchar *end;
g_return_val_if_fail (text != NULL, FALSE);
if (length < 0)
{
length = strlen (text);
}
p = text;
end = text + length;
end = text + strlen (text);
while (p != NULL && *p != '\0')
{
......
......@@ -25,8 +25,7 @@
G_BEGIN_DECLS
gboolean gedit_spell_utils_is_digit (const gchar *text,
gssize length);
gboolean gedit_spell_utils_is_digit (const gchar *text);
gboolean gedit_spell_utils_skip_no_spell_check (GtkTextIter *start,
GtkTextIter *end);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment