[gspell] checker: add string length parameter to add_word_to_personal()



commit 682da371ed14f6517fa9fb703c4bd60b236f7637
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Nov 22 18:32:37 2015 +0100

    checker: add string length parameter to add_word_to_personal()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758455

 gspell/gspell-checker-dialog.c     |    2 +-
 gspell/gspell-checker.c            |   24 +++++++++++++++++++++---
 gspell/gspell-checker.h            |    3 ++-
 gspell/gspell-inline-checker-gtv.c |    2 +-
 4 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/gspell/gspell-checker-dialog.c b/gspell/gspell-checker-dialog.c
index c413109..3c31b55 100644
--- a/gspell/gspell-checker-dialog.c
+++ b/gspell/gspell-checker-dialog.c
@@ -526,7 +526,7 @@ add_word_button_clicked_handler (GtkButton           *button,
 
        g_return_if_fail (priv->misspelled_word != NULL);
 
-       gspell_checker_add_word_to_personal (priv->checker, priv->misspelled_word);
+       gspell_checker_add_word_to_personal (priv->checker, priv->misspelled_word, -1);
 
        goto_next (dialog);
 }
diff --git a/gspell/gspell-checker.c b/gspell/gspell-checker.c
index e54b7dd..c7c1b37 100644
--- a/gspell/gspell-checker.c
+++ b/gspell/gspell-checker.c
@@ -536,25 +536,43 @@ gspell_checker_get_suggestions (GspellChecker *checker,
  * gspell_checker_add_word_to_personal:
  * @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 personal dictionary. It is typically saved in the user
  * home directory.
  */
 void
 gspell_checker_add_word_to_personal (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 (priv->dict, word, -1);
+       enchant_dict_add (priv->dict, word, word_length);
+
+       if (word_length == -1)
+       {
+               g_signal_emit (G_OBJECT (checker),
+                              signals[SIGNAL_ADD_WORD_TO_PERSONAL], 0,
+                              word);
+       }
+       else
+       {
+               gchar *nul_terminated_word = g_strndup (word, word_length);
+
+               g_signal_emit (G_OBJECT (checker),
+                              signals[SIGNAL_ADD_WORD_TO_PERSONAL], 0,
+                              nul_terminated_word);
 
-       g_signal_emit (G_OBJECT (checker), signals[SIGNAL_ADD_WORD_TO_PERSONAL], 0, word);
+               g_free (nul_terminated_word);
+       }
 }
 
 /**
diff --git a/gspell/gspell-checker.h b/gspell/gspell-checker.h
index 11f4c8d..81f38ea 100644
--- a/gspell/gspell-checker.h
+++ b/gspell/gspell-checker.h
@@ -95,7 +95,8 @@ GSList *      gspell_checker_get_suggestions          (GspellChecker *checker,
                                                         gssize         word_length);
 
 void           gspell_checker_add_word_to_personal     (GspellChecker *checker,
-                                                        const gchar   *word);
+                                                        const gchar   *word,
+                                                        gssize         word_length);
 
 void           gspell_checker_add_word_to_session      (GspellChecker *checker,
                                                         const gchar   *word);
diff --git a/gspell/gspell-inline-checker-gtv.c b/gspell/gspell-inline-checker-gtv.c
index 1677659..30cb768 100644
--- a/gspell/gspell-inline-checker-gtv.c
+++ b/gspell/gspell-inline-checker-gtv.c
@@ -503,7 +503,7 @@ add_to_dictionary_cb (GtkWidget              *menu_item,
 
        word = gtk_text_buffer_get_text (spell->buffer, &start, &end, FALSE);
 
-       gspell_checker_add_word_to_personal (spell->spell_checker, word);
+       gspell_checker_add_word_to_personal (spell->spell_checker, word, -1);
 
        g_free (word);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]