* 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
This commit is contained in:
Jürgen Spitzmüller 2010-02-10 10:24:10 +00:00
parent 94761bb7e5
commit 59d384f02b
4 changed files with 31 additions and 19 deletions

View File

@ -183,11 +183,14 @@ SpellChecker::Result HunspellChecker::check(WordLangTuple const & wl)
if (d->isIgnored(wl)) if (d->isIgnored(wl))
return OK; return OK;
string const word_to_check = to_utf8(wl.word());
Hunspell * h = d->speller(wl.lang()->code()); Hunspell * h = d->speller(wl.lang()->code());
if (!h) if (!h)
return OK; return OK;
int info; 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)) if (h->spell(word_to_check.c_str(), &info))
return OK; return OK;
@ -224,16 +227,17 @@ void HunspellChecker::suggest(WordLangTuple const & wl,
docstring_list & suggestions) docstring_list & suggestions)
{ {
suggestions.clear(); suggestions.clear();
string const word_to_check = to_utf8(wl.word());
Hunspell * h = d->speller(wl.lang()->code()); Hunspell * h = d->speller(wl.lang()->code());
if (!h) if (!h)
return; return;
string const encoding = h->get_dic_encoding();
string const word_to_check = to_iconv_encoding(wl.word(), encoding);
char ** suggestion_list; char ** suggestion_list;
int const suggestion_number = h->suggest(&suggestion_list, word_to_check.c_str()); int const suggestion_number = h->suggest(&suggestion_list, word_to_check.c_str());
if (suggestion_number <= 0) if (suggestion_number <= 0)
return; return;
for (int i = 0; i != suggestion_number; ++i) 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); h->free_list(&suggestion_list, suggestion_number);
} }

View File

@ -21,7 +21,6 @@
#include "support/gettext.h" #include "support/gettext.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/os.h" #include "support/os.h"
#include "support/unicode.h"
#include "support/mythes/mythes.hxx" #include "support/mythes/mythes.hxx"
@ -38,21 +37,6 @@ namespace lyx {
namespace { namespace {
string const to_iconv_encoding(docstring const & s, string const & encoding)
{
std::vector<char> 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<char_type> const ucs4 =
eightbit_to_ucs4(s.data(), s.length(), encoding);
return docstring(ucs4.begin(), ucs4.end());
}
typedef std::map<docstring, MyThes *> Thesauri; typedef std::map<docstring, MyThes *> Thesauri;
} // namespace anon } // namespace anon

View File

@ -152,6 +152,22 @@ string const to_filesystem8bit(docstring const & s)
} }
string const to_iconv_encoding(docstring const & s, string const & encoding)
{
std::vector<char> 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<char_type> const ucs4 =
eightbit_to_ucs4(s.data(), s.length(), encoding);
return docstring(ucs4.begin(), ucs4.end());
}
docstring const normalize_c(docstring const & s) docstring const normalize_c(docstring const & s)
{ {
return qstring_to_ucs4(toqstr(s).normalized(QString::NormalizationForm_C)); return qstring_to_ucs4(toqstr(s).normalized(QString::NormalizationForm_C));

View File

@ -57,6 +57,14 @@ docstring const from_filesystem8bit(std::string const & s);
/// convert \p s from ucs4 to the encoding of the file system. /// convert \p s from ucs4 to the encoding of the file system.
std::string const to_filesystem8bit(docstring const & s); 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 /// normalize \p s to precomposed form c
docstring const normalize_c(docstring const & s); docstring const normalize_c(docstring const & s);