From 690402f2e18e9a944b77147de4b3a678cca6d162 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Wed, 6 Oct 2021 20:08:48 +0200 Subject: Unbreak stardict_dict_get_synonyms() Untested, but certainly broken six ways to Sunday before. --- src/stardict.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/stardict.c b/src/stardict.c index 2d49aad..a757590 100644 --- a/src/stardict.c +++ b/src/stardict.c @@ -867,11 +867,12 @@ stardict_dict_cmp_synonym (StardictDict *sd, const gchar *word, gint i) g_array_index (synonyms, StardictSynonymEntry, i).word); } -/// Return words for which the argument is a synonym of or NULL +/// Return words of which the argument is a synonym or NULL /// if there are no such words. gchar ** stardict_dict_get_synonyms (StardictDict *sd, const gchar *word) { + GArray *collated = sd->priv->collated_synonyms; GArray *synonyms = sd->priv->synonyms; GArray *index = sd->priv->index; @@ -879,26 +880,32 @@ stardict_dict_get_synonyms (StardictDict *sd, const gchar *word) stardict_dict_cmp_synonym (sd, word, imid)) // Back off to the first matching entry - while (imid > 0 && !stardict_dict_cmp_synonym (sd, word, --imid)) - ; + while (imid > 0 && !stardict_dict_cmp_synonym (sd, word, imid - 1)) + imid--; GPtrArray *array = g_ptr_array_new (); // And add all matching entries from that position on to the array do { - guint32 i = g_array_index - (synonyms, StardictSynonymEntry, ++imid).original_word; + guint32 i = sd->priv->collator + ? g_array_index (synonyms, StardictSynonymEntry, + g_array_index (collated, guint32, imid)).original_word + : g_array_index (synonyms, StardictSynonymEntry, + imid).original_word; + // When we use a collator this will point to the original entry, // otherwise it points to itself and this changes nothing - i = g_array_index - (sd->priv->index, StardictIndexEntry, i).reverse_index; - g_ptr_array_add (array, g_strdup (g_array_index - (index, StardictIndexEntry, i).name)); + i = g_array_index (sd->priv->index, StardictIndexEntry, + i).reverse_index; + + g_ptr_array_add (array, + g_strdup (g_array_index (index, StardictIndexEntry, i).name)); } - while ((guint) imid < synonyms->len - 1 && !stardict_strcmp (word, - g_array_index (synonyms, StardictSynonymEntry, imid + 1).word)); + while ((guint) ++imid < synonyms->len + && !stardict_dict_cmp_synonym (sd, word, imid)); + g_ptr_array_add (array, NULL); return (gchar **) g_ptr_array_free (array, FALSE); BINARY_SEARCH_END -- cgit v1.2.3-70-g09d2