Support whitespace between language codes

So far, when configuring multiple spell check languages, Hexchat
requires the user to separate multiple entries with commas and
only commas. This patch allows users to also enter whitespace, e.g.

  de_DE, en_US

as is common in many applications.
This commit is contained in:
Andreas Schärtl 2022-09-01 18:22:29 +02:00 committed by Patrick
parent 46c9df1863
commit bd4290a1a9

View File

@ -1255,7 +1255,7 @@ void
sexy_spell_entry_activate_default_languages(SexySpellEntry *entry) sexy_spell_entry_activate_default_languages(SexySpellEntry *entry)
{ {
GSList *enchant_langs; GSList *enchant_langs;
char *lang, *langs; char *lang, **i, **langs;
if (!have_enchant) if (!have_enchant)
return; return;
@ -1265,21 +1265,21 @@ sexy_spell_entry_activate_default_languages(SexySpellEntry *entry)
enchant_langs = sexy_spell_entry_get_languages(entry); enchant_langs = sexy_spell_entry_get_languages(entry);
langs = g_strdup (prefs.hex_text_spell_langs); langs = g_strsplit_set (prefs.hex_text_spell_langs, ", \t", 0);
lang = strtok (langs, ","); for (i = langs; *i; i++)
while (lang != NULL)
{ {
lang = *i;
if (enchant_has_lang (lang, enchant_langs)) if (enchant_has_lang (lang, enchant_langs))
{ {
sexy_spell_entry_activate_language_internal (entry, lang, NULL); sexy_spell_entry_activate_language_internal (entry, lang, NULL);
} }
lang = strtok (NULL, ",");
} }
g_slist_foreach(enchant_langs, (GFunc) g_free, NULL); g_slist_foreach(enchant_langs, (GFunc) g_free, NULL);
g_slist_free(enchant_langs); g_slist_free(enchant_langs);
g_free (langs); g_strfreev (langs);
/* If we don't have any languages activated, use "en" */ /* If we don't have any languages activated, use "en" */
if (entry->priv->dict_list == NULL) if (entry->priv->dict_list == NULL)