From 3ce4572aa7959d992a79fa8fc689b0b538ca37a8 Mon Sep 17 00:00:00 2001 From: Dimitrij Mijoski Date: Fri, 20 Nov 2020 00:19:08 +0100 Subject: providers/enchant_nuspell.cpp: Improve code for provider Nuspell. Some improvements were made in Nuspell API in newer versions which can be used here: 1. Its spell() and suggest() accept string_view, there is no need for temporary std::string any more. 2. Use its new API for finding dictionaries as the old one is deprecated. --- providers/enchant_nuspell.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/providers/enchant_nuspell.cpp b/providers/enchant_nuspell.cpp index 1f10918..955caf9 100644 --- a/providers/enchant_nuspell.cpp +++ b/providers/enchant_nuspell.cpp @@ -74,9 +74,9 @@ NuspellChecker::checkWord(const char *utf8Word, size_t len) { // the 8-bit encodings use precomposed forms char *normalizedWord = g_utf8_normalize (utf8Word, len, G_NORMALIZE_NFC); - string s(normalizedWord); + auto ret = nuspell.spell(normalizedWord); g_free(normalizedWord); - return nuspell.spell(s); + return ret; } char** @@ -84,10 +84,9 @@ NuspellChecker::suggestWord(const char* const utf8Word, size_t len, size_t *nsug { // the 8-bit encodings use precomposed forms char *normalizedWord = g_utf8_normalize (utf8Word, len, G_NORMALIZE_NFC); - string s(normalizedWord); - g_free(normalizedWord); auto suggestions = vector(); - nuspell.suggest(s, suggestions); + nuspell.suggest(normalizedWord, suggestions); + g_free(normalizedWord); if (suggestions.empty()) return nullptr; *nsug = suggestions.size(); @@ -119,19 +118,14 @@ s_buildDictionaryDirs (vector & dirs) /* Dynamically retrieved from Nuspell dictionary finder: * 2. personal overrides for Hunspell - * ~/.local/share/hunspell + * $XDG_DATA_HOME/hunspell + * $XDG_DATA_HOME by default is $HOME/.local/share/ * 3. system installed for Hunspell - * /usr/local/share/hunspell - * /usr/share/hunspell - * 4. personal or system installations for - * Mozilla (such as Firefox and Thunderbird), - * LibreOffice and Apache OpenOffice + * $XDG_DATA_DIRS/hunspell + * $XDG_DATA_DIRS/myspell (needed for Fedora) + * $XDG_DATA_DIRS by default are /usr/local/share and /usr/share */ - auto nuspell_finder = nuspell::Finder::search_all_dirs_for_dicts(); - for (auto& path : nuspell_finder.get_dir_paths()) { - if (path.compare(".") != 0) - dirs.push_back (path.c_str()); - } + nuspell::append_default_dir_paths(dirs); /* 5. system installations by Enchant * /usr/local/share/enchant/nuspell -- cgit v1.2.1