]> git.lyx.org Git - lyx.git/blobdiff - src/aspell.C
fix typo in commit 16925
[lyx.git] / src / aspell.C
index 6d7a2fa27856606ce493d9202b211b81fec5bd12..69252704041db9471ae5ec63dd67acad668c261d 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file aspell_local.C
+ * \file aspell.C
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
@@ -11,9 +11,6 @@
 
 #include <config.h>
 
-#ifdef USE_ASPELL
-
-#include "support/LAssert.h"
 #include "debug.h"
 
 #include <aspell.h>
 #include "aspell_local.h"
 #include "WordLangTuple.h"
 
+#include <boost/assert.hpp>
 
-using namespace lyx::support;
+using std::string;
 
+namespace lyx {
 
 ASpell::ASpell(BufferParams const &, string const & lang)
        : els(0), spell_error_object(0)
@@ -56,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);
@@ -73,9 +81,9 @@ void ASpell::addSpeller(string const & lang)
 }
 
 
-enum ASpell::Result ASpell::check(WordLangTuple const & word)
+ASpell::Result ASpell::check(WordLangTuple const & word)
 {
-       Result res = UNKNOWN;
+       Result res = UNKNOWN_WORD;
 
        Spellers::iterator it = spellers_.find(word.lang_code());
        if (it == spellers_.end()) {
@@ -88,20 +96,20 @@ enum ASpell::Result ASpell::check(WordLangTuple const & word)
 
        AspellSpeller * m = it->second.speller;
 
-       int word_ok = aspell_speller_check(m, word.word().c_str(), -1);
-       Assert(word_ok != -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);
-               Assert(sugs != 0);
+                       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))
-                       res = UNKNOWN;
+                       res = UNKNOWN_WORD;
                else
-                       res = MISSED;
+                       res = SUGGESTED_WORDS;
        }
        return res;
 }
@@ -111,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);
 }
 
 
@@ -119,33 +127,32 @@ 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);
-       if (str)
-               return str;
-       return "";
+
+       return (str ? from_utf8(str) : docstring());
 }
 
 
-string const ASpell::error()
+docstring const ASpell::error()
 {
        char const * err = 0;
-
+       
        if (spell_error_object && aspell_error_number(spell_error_object) != 0) {
                err = aspell_error_message(spell_error_object);
        }
 
-       if (err)
-               return err;
-       return "";
+       // FIXME UNICODE: err is not in UTF8, but probably the locale encoding
+       return (err ? from_utf8(err) : docstring());
 }
 
-#endif // USE_ASPELL
+
+} // namespace lyx