[gtk/wip/chergert/spellcheck: 193/194] spellcheck: deduplicate languages from checker
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/spellcheck: 193/194] spellcheck: deduplicate languages from checker
- Date: Mon, 29 Mar 2021 20:38:27 +0000 (UTC)
commit 2b67166a38bed54713028da03e070c4e4a490b3e
Author: Christian Hergert <chergert redhat com>
Date: Mon Mar 15 15:32:47 2021 -0700
spellcheck: deduplicate languages from checker
We don't want the same language loaded twice which could occur if we had
something like "en_US" and "en_US.UTF-8" which is turned into "en_US" by
enchant internally.
gtk/gtkspellcheck.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkspellcheck.c b/gtk/gtkspellcheck.c
index bfed875074..34de75b89f 100644
--- a/gtk/gtkspellcheck.c
+++ b/gtk/gtkspellcheck.c
@@ -146,6 +146,26 @@ gtk_spell_checker_get_languages (GtkSpellChecker *self)
return (char **)(gpointer)g_array_free (ar, FALSE);
}
+static gboolean
+gtk_spell_checker_contains_language (GtkSpellChecker *self,
+ GtkSpellLanguage *language)
+{
+ g_assert (GTK_IS_SPELL_CHECKER (self));
+ g_assert (language != NULL);
+ g_assert (language->code != NULL);
+ g_assert (language->provider != NULL);
+
+ for (guint i = 0; i < self->languages->len; i++)
+ {
+ GtkSpellLanguage *element = g_ptr_array_index (self->languages, i);
+
+ if (g_strcmp0 (language->code, element->code) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
gtk_spell_checker_set_languages (GtkSpellChecker *self,
const char * const *languages)
@@ -165,7 +185,9 @@ gtk_spell_checker_set_languages (GtkSpellChecker *self,
if (language == NULL)
continue;
- g_ptr_array_add (self->languages, language);
+ if (!gtk_spell_checker_contains_language (self, language))
+ g_ptr_array_add (self->languages, language);
+
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]