[gspell] checker: add string length parameter to add_word_to_session()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell] checker: add string length parameter to add_word_to_session()
- Date: Sun, 22 Nov 2015 17:38:57 +0000 (UTC)
commit 25de4b4967183a0d7f842fddc25c70305a982a49
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Nov 22 18:37:38 2015 +0100
checker: add string length parameter to add_word_to_session()
https://bugzilla.gnome.org/show_bug.cgi?id=758455
gspell/gspell-checker-dialog.c | 2 +-
gspell/gspell-checker.c | 26 ++++++++++++++++++++++----
gspell/gspell-checker.h | 3 ++-
gspell/gspell-inline-checker-gtv.c | 2 +-
4 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/gspell/gspell-checker-dialog.c b/gspell/gspell-checker-dialog.c
index 3c31b55..1e4717c 100644
--- a/gspell/gspell-checker-dialog.c
+++ b/gspell/gspell-checker-dialog.c
@@ -548,7 +548,7 @@ ignore_all_button_clicked_handler (GtkButton *button,
g_return_if_fail (priv->misspelled_word != NULL);
- gspell_checker_add_word_to_session (priv->checker, priv->misspelled_word);
+ gspell_checker_add_word_to_session (priv->checker, priv->misspelled_word, -1);
goto_next (dialog);
}
diff --git a/gspell/gspell-checker.c b/gspell/gspell-checker.c
index c7c1b37..f177d5b 100644
--- a/gspell/gspell-checker.c
+++ b/gspell/gspell-checker.c
@@ -360,7 +360,7 @@ init_dictionary (GspellChecker *checker)
}
app_name = g_get_application_name ();
- gspell_checker_add_word_to_session (checker, app_name);
+ gspell_checker_add_word_to_session (checker, app_name, -1);
return TRUE;
}
@@ -579,6 +579,7 @@ gspell_checker_add_word_to_personal (GspellChecker *checker,
* gspell_checker_add_word_to_session:
* @checker: a #GspellChecker.
* @word: a word.
+ * @word_length: the byte length of @word, or -1 if @word is nul-terminated.
*
* Adds a word to the session dictionary. The session dictionary is lost when
* the application exits. This function is typically called when an “Ignore All”
@@ -586,19 +587,36 @@ gspell_checker_add_word_to_personal (GspellChecker *checker,
*/
void
gspell_checker_add_word_to_session (GspellChecker *checker,
- const gchar *word)
+ const gchar *word,
+ gssize word_length)
{
GspellCheckerPrivate *priv;
g_return_if_fail (GSPELL_IS_CHECKER (checker));
g_return_if_fail (word != NULL);
+ g_return_if_fail (word_length >= -1);
g_return_if_fail (_gspell_checker_check_language_set (checker));
priv = gspell_checker_get_instance_private (checker);
- enchant_dict_add_to_session (priv->dict, word, -1);
+ enchant_dict_add_to_session (priv->dict, word, word_length);
+
+ if (word_length == -1)
+ {
+ g_signal_emit (G_OBJECT (checker),
+ signals[SIGNAL_ADD_WORD_TO_SESSION], 0,
+ word);
+ }
+ else
+ {
+ gchar *nul_terminated_word = g_strndup (word, word_length);
+
+ g_signal_emit (G_OBJECT (checker),
+ signals[SIGNAL_ADD_WORD_TO_SESSION], 0,
+ nul_terminated_word);
- g_signal_emit (G_OBJECT (checker), signals[SIGNAL_ADD_WORD_TO_SESSION], 0, word);
+ g_free (nul_terminated_word);
+ }
}
/**
diff --git a/gspell/gspell-checker.h b/gspell/gspell-checker.h
index 81f38ea..077e708 100644
--- a/gspell/gspell-checker.h
+++ b/gspell/gspell-checker.h
@@ -99,7 +99,8 @@ void gspell_checker_add_word_to_personal (GspellChecker *checker,
gssize word_length);
void gspell_checker_add_word_to_session (GspellChecker *checker,
- const gchar *word);
+ const gchar *word,
+ gssize word_length);
void gspell_checker_clear_session (GspellChecker *checker);
diff --git a/gspell/gspell-inline-checker-gtv.c b/gspell/gspell-inline-checker-gtv.c
index 30cb768..4651422 100644
--- a/gspell/gspell-inline-checker-gtv.c
+++ b/gspell/gspell-inline-checker-gtv.c
@@ -523,7 +523,7 @@ ignore_all_cb (GtkWidget *menu_item,
word = gtk_text_buffer_get_text (spell->buffer, &start, &end, FALSE);
- gspell_checker_add_word_to_session (spell->spell_checker, word);
+ gspell_checker_add_word_to_session (spell->spell_checker, word, -1);
g_free (word);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]