X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Faspell.C;h=69252704041db9471ae5ec63dd67acad668c261d;hb=c727c6db7f2dd7f6a727462f5d11964888d0e76e;hp=78f677475c0edba278bbf353711bfb29a7194257;hpb=6c300f72a217722652dc27db9108e1050028979c;p=lyx.git diff --git a/src/aspell.C b/src/aspell.C index 78f677475c..6925270404 100644 --- a/src/aspell.C +++ b/src/aspell.C @@ -20,13 +20,9 @@ #include - -namespace lyx { - -using docstring; - using std::string; +namespace lyx { ASpell::ASpell(BufferParams const &, string const & lang) : els(0), spell_error_object(0) @@ -59,7 +55,16 @@ ASpell::~ASpell() void ASpell::addSpeller(string const & lang) { AspellConfig * config = new_aspell_config(); + // FIXME The aspell documentation says to use "lang" aspell_config_replace(config, "language-tag", lang.c_str()); + // Set the encoding to utf-8. + // aspell does also understand "ucs-4", so we would not need a + // conversion in theory, but if this is used it expects all + // char const * arguments to be a cast from uint const *, and it + // seems that this uint is not compatible with our char_type on some + // platforms (cygwin, OS X). Therefore we use utf-8, that does + // always work. + aspell_config_replace(config, "encoding", "utf-8"); AspellCanHaveError * err = new_aspell_speller(config); if (spell_error_object) delete_aspell_can_have_error(spell_error_object); @@ -91,14 +96,14 @@ ASpell::Result ASpell::check(WordLangTuple const & word) AspellSpeller * m = it->second.speller; - int const word_ok = aspell_speller_check(m, word.word().c_str(), -1); + int const word_ok = aspell_speller_check(m, to_utf8(word.word()).c_str(), -1); BOOST_ASSERT(word_ok != -1); if (word_ok) { res = OK; } else { AspellWordList const * sugs = - aspell_speller_suggest(m, word.word().c_str(), -1); + aspell_speller_suggest(m, to_utf8(word.word()).c_str(), -1); BOOST_ASSERT(sugs != 0); els = aspell_word_list_elements(sugs); if (aspell_word_list_empty(sugs)) @@ -114,7 +119,7 @@ void ASpell::insert(WordLangTuple const & word) { Spellers::iterator it = spellers_.find(word.lang_code()); if (it != spellers_.end()) - aspell_speller_add_to_personal(it->second.speller, word.word().c_str(), -1); + aspell_speller_add_to_personal(it->second.speller, to_utf8(word.word()).c_str(), -1); } @@ -122,18 +127,18 @@ void ASpell::accept(WordLangTuple const & word) { Spellers::iterator it = spellers_.find(word.lang_code()); if (it != spellers_.end()) - aspell_speller_add_to_session(it->second.speller, word.word().c_str(), -1); + aspell_speller_add_to_session(it->second.speller, to_utf8(word.word()).c_str(), -1); } -string const ASpell::nextMiss() +docstring const ASpell::nextMiss() { char const * str = 0; if (els) str = aspell_string_enumeration_next(els); - return (str ? str : ""); + return (str ? from_utf8(str) : docstring()); } @@ -145,6 +150,7 @@ docstring const ASpell::error() err = aspell_error_message(spell_error_object); } + // FIXME UNICODE: err is not in UTF8, but probably the locale encoding return (err ? from_utf8(err) : docstring()); }