]> git.lyx.org Git - features.git/commitdiff
Convert the spell checking machinery to docstring.
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 8 Dec 2006 19:46:16 +0000 (19:46 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 8 Dec 2006 19:46:16 +0000 (19:46 +0000)
Fix a conversion char -> char_type without encoding conversion in
cap::replaceSelectionWithString().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16212 a592a061-630c-0410-9148-cb99ea01b6c8

15 files changed:
src/CutAndPaste.C
src/CutAndPaste.h
src/SpellBase.C
src/SpellBase.h
src/WordLangTuple.h
src/aspell.C
src/aspell_local.h
src/frontends/controllers/ControlSpellchecker.C
src/frontends/controllers/ControlSpellchecker.h
src/frontends/qt4/QSpellchecker.C
src/ispell.C
src/ispell.h
src/lyxfind.C
src/pspell.C
src/pspell.h

index c2ddae5c60dfcd7720ca3933fb553b34cf921502..d82aab8faa82d0c5597035705fc66eefc5568ac4 100644 (file)
@@ -649,7 +649,7 @@ void pasteSelection(LCursor & cur, ErrorList & errorList, size_t sel_index)
 
 
 // simple replacing. The font of the first selected character is used
-void replaceSelectionWithString(LCursor & cur, string const & str, bool backwards)
+void replaceSelectionWithString(LCursor & cur, docstring const & str, bool backwards)
 {
        recordUndo(cur);
        DocIterator selbeg = cur.selectionBegin();
@@ -661,10 +661,10 @@ void replaceSelectionWithString(LCursor & cur, string const & str, bool backward
        // Insert the new string
        pos_type pos = cur.selEnd().pos();
        Paragraph & par = cur.selEnd().paragraph();
-       string::const_iterator cit = str.begin();
-       string::const_iterator end = str.end();
+       docstring::const_iterator cit = str.begin();
+       docstring::const_iterator end = str.end();
        for (; cit != end; ++cit, ++pos)
-               par.insertChar(pos, (*cit), font, cur.buffer().params().trackChanges);
+               par.insertChar(pos, *cit, font, cur.buffer().params().trackChanges);
 
        // Cut the selection
        cutSelection(cur, true, false);
index 332e414002b322570e2844bc3ad516229b7721da..eb6aded2e23dc70804298cdef429184333ee7d7b 100644 (file)
@@ -44,7 +44,7 @@ void cutSelection(LCursor & cur, bool doclear, bool realcut);
  * the new string. When \c backwards == false, set anchor before
  * cursor; otherwise set cursor before anchor.
  */
-void replaceSelectionWithString(LCursor & cur, std::string const & str, 
+void replaceSelectionWithString(LCursor & cur, docstring const & str,
                                bool backwards);
 /// replace selection helper
 void replaceSelection(LCursor & cur);
index b8b212b6a47a87d1e1e52d6dd0cf660915756c20..e2935de1632aa9f5f4c94b6043a72978fe79a567 100644 (file)
@@ -40,9 +40,9 @@ void SpellBase::accept(WordLangTuple const &)
 {}
 
 
-string const SpellBase::nextMiss()
+docstring const SpellBase::nextMiss()
 {
-       return string();
+       return docstring();
 }
 
 
index f9f2a4a7328c62a2d84c64135915dd3acf6eb898..e4ec616bdc360ef641051d1d6eeac0d9d6857bda 100644 (file)
@@ -15,8 +15,6 @@
 
 #include "support/docstring.h"
 
-#include <string>
-
 
 namespace lyx {
 
@@ -61,7 +59,7 @@ public:
        virtual void accept(WordLangTuple const &);
 
        /// return the next near miss after a SUGGESTED_WORDS result
-       virtual std::string const nextMiss();
+       virtual docstring const nextMiss();
 
        /// give an error message on messy exit
        virtual docstring const error();
index 9e2232bd3d1b199c1c0e63b22a7f23ba8300dd77..b1a31bd90d27509345d2168604cd7239f49f1857 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef WORD_LANG_TUPLE_H
 #define WORD_LANG_TUPLE_H
 
-#include <string>
+#include "support/docstring.h"
 
 
 namespace lyx {
@@ -26,12 +26,12 @@ class WordLangTuple {
 public:
        WordLangTuple() {}
 
-       WordLangTuple(std::string const & w, std::string const & c)
+       WordLangTuple(docstring const & w, std::string const & c)
                : word_(w), code_(c)
        {}
 
        /// return the word
-       std::string const & word() const {
+       docstring const & word() const {
                return word_;
        }
 
@@ -42,7 +42,7 @@ public:
 
 private:
        /// the word
-       std::string word_;
+       docstring word_;
        /// language code of word
        std::string code_;
 };
index f9caa75233a690270ba6c0259b50f89d9f8a69e1..631945c24f533cb1a977646bc1d4b2b9fbd2c304 100644 (file)
@@ -87,14 +87,16 @@ 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);
+       // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+       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 {
+               // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
                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))
@@ -110,7 +112,8 @@ 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);
+               // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+               aspell_speller_add_to_personal(it->second.speller, to_utf8(word.word()).c_str(), -1);
 }
 
 
@@ -118,18 +121,20 @@ 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);
+               // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+               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 : "");
+       // FIXME UNICODE: str is not in UTF8, but probably the locale encoding
+       return (str ? from_utf8(str) : docstring());
 }
 
 
@@ -141,6 +146,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());
 }
 
index 1b45c704513e3fcf23a9cd9104d9bc93bf62858b..f7e840d5f45e44b5dbe0333d7489bba0b8e5f4e4 100644 (file)
@@ -15,8 +15,6 @@
 
 #include "SpellBase.h"
 
-#include "support/docstring.h"
-
 #include <map>
 
 
@@ -55,7 +53,7 @@ public:
        virtual void accept(WordLangTuple const &);
 
        /// return the next near miss after a SUGGESTED_WORDS result
-       virtual std::string const nextMiss();
+       virtual docstring const nextMiss();
 
        /// give an error message on messy exit
        virtual docstring const error();
index d5e1fdb86dbaacf81d53164009df9b03287971ac..c001bd27b4ed4339f28906bcf15057539a420d33 100644 (file)
@@ -173,7 +173,7 @@ WordLangTuple nextWord(LCursor & cur, ptrdiff_t & progress)
                        if (inword)
                                if (!word.empty() && !ignoreword) {
                                        cur.setSelection();
-                                       return WordLangTuple(lyx::to_utf8(word), lang_code);
+                                       return WordLangTuple(word, lang_code);
                                } else
                                        inword = false;
                }
@@ -182,7 +182,7 @@ WordLangTuple nextWord(LCursor & cur, ptrdiff_t & progress)
                ++progress;
        }
 
-       return WordLangTuple(string(), string());
+       return WordLangTuple(docstring(), string());
 }
 
 } // namespace anon
@@ -243,7 +243,7 @@ void ControlSpellchecker::check()
                        return;
        }
 
-       lyxerr[Debug::GUI] << "Found word \"" << getWord() << "\"" << endl;
+       lyxerr[Debug::GUI] << "Found word \"" << to_utf8(getWord()) << "\"" << endl;
 
        int const size = cur.selEnd().pos() - cur.selBegin().pos();
        cur.pos() -= size;
@@ -297,10 +297,10 @@ void ControlSpellchecker::showSummary()
 }
 
 
-void ControlSpellchecker::replace(string const & replacement)
+void ControlSpellchecker::replace(docstring const & replacement)
 {
        lyxerr[Debug::GUI] << "ControlSpellchecker::replace("
-                          << replacement << ")" << std::endl;
+                          << to_utf8(replacement) << ")" << std::endl;
        BufferView & bufferview = *kernel().bufferview();
        cap::replaceSelectionWithString(bufferview.cursor(), replacement, true);
        kernel().buffer().markDirty();
@@ -312,7 +312,7 @@ void ControlSpellchecker::replace(string const & replacement)
 }
 
 
-void ControlSpellchecker::replaceAll(string const & replacement)
+void ControlSpellchecker::replaceAll(docstring const & replacement)
 {
        // TODO: add to list
        replace(replacement);
@@ -326,13 +326,13 @@ void ControlSpellchecker::insert()
 }
 
 
-string const ControlSpellchecker::getSuggestion() const
+docstring const ControlSpellchecker::getSuggestion() const
 {
        return speller_->nextMiss();
 }
 
 
-string const ControlSpellchecker::getWord() const
+docstring const ControlSpellchecker::getWord() const
 {
        return word_.word();
 }
index 4f99f6d892840a7cdf75e22c45634bb1e75d8197..6b19f66175d8fa2affecba4ff1630aed6080bd4f 100644 (file)
@@ -45,10 +45,10 @@ public:
        virtual bool exitEarly() const { return exitEarly_; }
 
        /// replace word with replacement
-       void replace(std::string const &);
+       void replace(docstring const &);
 
        /// replace all occurances of word
-       void replaceAll(std::string const &);
+       void replaceAll(docstring const &);
 
        /// insert word in personal dictionary
        void insert();
@@ -61,10 +61,10 @@ public:
        void check();
 
        /// get suggestion
-       std::string const getSuggestion() const;
+       docstring const getSuggestion() const;
 
        /// get word
-       std::string const getWord() const;
+       docstring const getWord() const;
 
        /// returns progress value
        int getProgress() const { return oldval_; }
index a07dbeb98df8252d0f4ebf51da47ce6be0935d38..30bc8cb4d531a9086edb5e407ce1db86872a5ed6 100644 (file)
@@ -72,7 +72,7 @@ void QSpellchecker::ignore()
 
 void QSpellchecker::replace()
 {
-       controller().replace(fromqstr(dialog_->replaceCO->currentText()));
+       controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
 }
 
 
@@ -91,7 +91,7 @@ void QSpellchecker::partialUpdate(int s)
                dialog_->wordED->setText(toqstr(controller().getWord()));
                dialog_->suggestionsLW->clear();
 
-               string w;
+               docstring w;
                while (!(w = controller().getSuggestion()).empty()) {
                        dialog_->suggestionsLW->addItem(toqstr(w));
                }
index ab7dfcb89cac694017d7e8c1f1b041f91fa76e28..87613ade36420dd34853b74aea93990ba363fe0f 100644 (file)
@@ -252,7 +252,7 @@ ISpell::ISpell(BufferParams const & params, string const & lang)
                return;
        }
 
-       /* Parent process: Read ispells identification message */
+       // Parent process: Read ispells identification message
 
        bool err_read;
        bool error = select(err_read);
@@ -264,7 +264,8 @@ ISpell::ISpell(BufferParams const & params, string const & lang)
                        return;
                }
 
-               /* must have read something from stderr */
+               // must have read something from stderr
+               // FIXME UNICODE: buf is not in UTF8, but probably the locale encoding
                error_ =from_utf8(buf);
        } else {
                // select returned error
@@ -343,18 +344,19 @@ bool ISpell::select(bool & err_read)
 }
 
 
-string const ISpell::nextMiss()
+docstring const ISpell::nextMiss()
 {
        // Well, somebody is a sick fuck.
 
        if (str == 0 || *(e+1) == '\0')
-               return "";
+               return docstring();
        char * b = e + 2;
        e = strpbrk(b, ",\n");
        *e = '\0';
        if (b)
-               return b;
-       return "";
+               // FIXME UNICODE: b is not in UTF8, but probably the locale encoding
+               return from_utf8(b);
+       return docstring();
 }
 
 
@@ -370,7 +372,8 @@ enum ISpell::Result ISpell::check(WordLangTuple const & word)
 
        Result res;
 
-       ::fputs(word.word().c_str(), out);
+       // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+       ::fputs(to_utf8(word.word()).c_str(), out);
        ::fputc('\n', out);
 
        bool err_read;
@@ -382,6 +385,7 @@ enum ISpell::Result ISpell::check(WordLangTuple const & word)
        }
 
        if (err_read) {
+               // FIXME UNICODE: buf is not in UTF8, but probably the locale encoding
                error_ = from_utf8(buf);
                return UNKNOWN_WORD;
        }
@@ -434,7 +438,8 @@ enum ISpell::Result ISpell::check(WordLangTuple const & word)
 void ISpell::insert(WordLangTuple const & word)
 {
        ::fputc('*', out); // Insert word in personal dictionary
-       ::fputs(word.word().c_str(), out);
+       // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+       ::fputs(to_utf8(word.word()).c_str(), out);
        ::fputc('\n', out);
 }
 
@@ -442,7 +447,8 @@ void ISpell::insert(WordLangTuple const & word)
 void ISpell::accept(WordLangTuple const & word)
 {
        ::fputc('@', out); // Accept in this session
-       ::fputs(word.word().c_str(), out);
+       // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+       ::fputs(to_utf8(word.word()).c_str(), out);
        ::fputc('\n', out);
 }
 
index 0fe77a15bc261f46b60e92dfdb897675b36b5d71..613c9d208c7e9faa5bedf53e6461c77c0b8e8867 100644 (file)
@@ -47,7 +47,7 @@ public:
        virtual void accept(WordLangTuple const & word);
 
        /// return the next near miss after a SUGGESTED_WORDS result
-       virtual std::string const nextMiss();
+       virtual docstring const nextMiss();
 
        /// give an error message on messy exit
        virtual docstring const error();
index 98f30e15d3ae62d39b87d2c5959ebe17133bfba0..93797a61596551b7bd0247479d76d597fdcb38ea 100644 (file)
@@ -218,7 +218,7 @@ bool stringSelected(BufferView * bv, string const & searchstr,
 
 
 int replace(BufferView * bv, string const & searchstr,
-           string const & replacestr, bool cs, bool mw, bool fw)
+           std::string const & replacestr, bool cs, bool mw, bool fw)
 {
        if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
                return 0;
@@ -227,7 +227,7 @@ int replace(BufferView * bv, string const & searchstr,
                return 0;
 
        LCursor & cur = bv->cursor();
-       cap::replaceSelectionWithString(cur, replacestr, fw);
+       cap::replaceSelectionWithString(cur, from_utf8(replacestr), fw);
        bv->buffer()->markDirty();
        find(bv, searchstr, cs, mw, fw);
        bv->update();
index 9d876c1ff825452f0b18bcfd7929fb81d2c987a0..042161efb7c8c4dc2a6831dad0b3fa09522a7820 100644 (file)
@@ -97,14 +97,16 @@ enum PSpell::Result PSpell::check(WordLangTuple const & word)
 
        PspellManager * m = it->second.manager;
 
-       int word_ok = pspell_manager_check(m, word.word().c_str());
+       // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+       int word_ok = pspell_manager_check(m, to_utf8(word.word()).c_str());
        BOOST_ASSERT(word_ok != -1);
 
        if (word_ok) {
                res = OK;
        } else {
+               // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
                PspellWordList const * sugs =
-                       pspell_manager_suggest(m, word.word().c_str());
+                       pspell_manager_suggest(m, to_utf8(word.word()).c_str());
                BOOST_ASSERT(sugs != 0);
                els = pspell_word_list_elements(sugs);
                if (pspell_word_list_empty(sugs))
@@ -120,7 +122,8 @@ void PSpell::insert(WordLangTuple const & word)
 {
        Managers::iterator it = managers_.find(word.lang_code());
        if (it != managers_.end())
-               pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
+               // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+               pspell_manager_add_to_personal(it->second.manager, to_utf8(word.word()).c_str());
 }
 
 
@@ -128,19 +131,21 @@ void PSpell::accept(WordLangTuple const & word)
 {
        Managers::iterator it = managers_.find(word.lang_code());
        if (it != managers_.end())
-               pspell_manager_add_to_session(it->second.manager, word.word().c_str());
+               // FIXME UNICODE: we don't need to convert to UTF8, but probably to the locale encoding
+               pspell_manager_add_to_session(it->second.manager, to_utf8(word.word()).c_str());
 }
 
 
-string const PSpell::nextMiss()
+docstring const PSpell::nextMiss()
 {
        char const * str = 0;
 
        if (els)
                str = pspell_string_emulation_next(els);
        if (str)
-               return str;
-       return "";
+               // FIXME UNICODE: str is not in UTF8, but probably the locale encoding
+               return from_utf8(str);
+       return docstring();
 }
 
 
index 7d2cfc14efbb858f6df7c5d11d2702a4f47aaaef..44071dc3e17d3647949aab433ed0cb21deef3c2d 100644 (file)
@@ -53,7 +53,7 @@ public:
        virtual void accept(WordLangTuple const &);
 
        /// return the next near miss after a SUGGESTED_WORDS result
-       virtual std::string const nextMiss();
+       virtual docstring const nextMiss();
 
        /// give an error message on messy exit
        virtual docstring const error();