From 59d384f02bf86709f0a97b54101e0e86fdf239cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Wed, 10 Feb 2010 10:24:10 +0000 Subject: [PATCH] * Thesaurus.cpp: * docstring.{cpp,h}: - move conversion functions to_iconv_encoding and from_iconv_encoding from Thesaurus to docstring. * HunspellChecker.cpp: - use correct encoding for string conversion. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33407 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/HunspellChecker.cpp | 10 +++++++--- src/Thesaurus.cpp | 16 ---------------- src/support/docstring.cpp | 16 ++++++++++++++++ src/support/docstring.h | 8 ++++++++ 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/HunspellChecker.cpp b/src/HunspellChecker.cpp index 8c47fdb070..e85338ddd4 100644 --- a/src/HunspellChecker.cpp +++ b/src/HunspellChecker.cpp @@ -183,11 +183,14 @@ SpellChecker::Result HunspellChecker::check(WordLangTuple const & wl) if (d->isIgnored(wl)) return OK; - string const word_to_check = to_utf8(wl.word()); Hunspell * h = d->speller(wl.lang()->code()); if (!h) return OK; int info; + + string const encoding = h->get_dic_encoding(); + string const word_to_check = to_iconv_encoding(wl.word(), encoding); + if (h->spell(word_to_check.c_str(), &info)) return OK; @@ -224,16 +227,17 @@ void HunspellChecker::suggest(WordLangTuple const & wl, docstring_list & suggestions) { suggestions.clear(); - string const word_to_check = to_utf8(wl.word()); Hunspell * h = d->speller(wl.lang()->code()); if (!h) return; + string const encoding = h->get_dic_encoding(); + string const word_to_check = to_iconv_encoding(wl.word(), encoding); char ** suggestion_list; int const suggestion_number = h->suggest(&suggestion_list, word_to_check.c_str()); if (suggestion_number <= 0) return; for (int i = 0; i != suggestion_number; ++i) - suggestions.push_back(from_utf8(suggestion_list[i])); + suggestions.push_back(from_iconv_encoding(suggestion_list[i], encoding)); h->free_list(&suggestion_list, suggestion_number); } diff --git a/src/Thesaurus.cpp b/src/Thesaurus.cpp index f3814baaf7..a0f15150f4 100644 --- a/src/Thesaurus.cpp +++ b/src/Thesaurus.cpp @@ -21,7 +21,6 @@ #include "support/gettext.h" #include "support/lstrings.h" #include "support/os.h" -#include "support/unicode.h" #include "support/mythes/mythes.hxx" @@ -38,21 +37,6 @@ namespace lyx { namespace { -string const to_iconv_encoding(docstring const & s, string const & encoding) -{ - std::vector const encoded = - ucs4_to_eightbit(s.data(), s.length(), encoding); - return string(encoded.begin(), encoded.end()); -} - - -docstring const from_iconv_encoding(string const & s, string const & encoding) -{ - std::vector const ucs4 = - eightbit_to_ucs4(s.data(), s.length(), encoding); - return docstring(ucs4.begin(), ucs4.end()); -} - typedef std::map Thesauri; } // namespace anon diff --git a/src/support/docstring.cpp b/src/support/docstring.cpp index b3417f7f26..86deda1d86 100644 --- a/src/support/docstring.cpp +++ b/src/support/docstring.cpp @@ -152,6 +152,22 @@ string const to_filesystem8bit(docstring const & s) } +string const to_iconv_encoding(docstring const & s, string const & encoding) +{ + std::vector const encoded = + ucs4_to_eightbit(s.data(), s.length(), encoding); + return string(encoded.begin(), encoded.end()); +} + + +docstring const from_iconv_encoding(string const & s, string const & encoding) +{ + std::vector const ucs4 = + eightbit_to_ucs4(s.data(), s.length(), encoding); + return docstring(ucs4.begin(), ucs4.end()); +} + + docstring const normalize_c(docstring const & s) { return qstring_to_ucs4(toqstr(s).normalized(QString::NormalizationForm_C)); diff --git a/src/support/docstring.h b/src/support/docstring.h index 22dd2ffa4c..5eea0111a3 100644 --- a/src/support/docstring.h +++ b/src/support/docstring.h @@ -57,6 +57,14 @@ docstring const from_filesystem8bit(std::string const & s); /// convert \p s from ucs4 to the encoding of the file system. std::string const to_filesystem8bit(docstring const & s); +/// convert \p s from ucs4 to the \p encoding. +std::string const to_iconv_encoding(docstring const & s, + std::string const & encoding); + +/// convert \p s from \p encoding to ucs4. +docstring const from_iconv_encoding(std::string const & s, + std::string const & encoding); + /// normalize \p s to precomposed form c docstring const normalize_c(docstring const & s);