From: Georg Baum Date: Fri, 8 Dec 2006 19:46:16 +0000 (+0000) Subject: Convert the spell checking machinery to docstring. X-Git-Tag: 1.6.10~11611 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=26460b39ee8b2c8fe88e3f2225486e1b72e59f3f;p=features.git Convert the spell checking machinery to docstring. 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 --- diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index c2ddae5c60..d82aab8faa 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -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); diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index 332e414002..eb6aded2e2 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -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); diff --git a/src/SpellBase.C b/src/SpellBase.C index b8b212b6a4..e2935de163 100644 --- a/src/SpellBase.C +++ b/src/SpellBase.C @@ -40,9 +40,9 @@ void SpellBase::accept(WordLangTuple const &) {} -string const SpellBase::nextMiss() +docstring const SpellBase::nextMiss() { - return string(); + return docstring(); } diff --git a/src/SpellBase.h b/src/SpellBase.h index f9f2a4a732..e4ec616bdc 100644 --- a/src/SpellBase.h +++ b/src/SpellBase.h @@ -15,8 +15,6 @@ #include "support/docstring.h" -#include - 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(); diff --git a/src/WordLangTuple.h b/src/WordLangTuple.h index 9e2232bd3d..b1a31bd90d 100644 --- a/src/WordLangTuple.h +++ b/src/WordLangTuple.h @@ -12,7 +12,7 @@ #ifndef WORD_LANG_TUPLE_H #define WORD_LANG_TUPLE_H -#include +#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_; }; diff --git a/src/aspell.C b/src/aspell.C index f9caa75233..631945c24f 100644 --- a/src/aspell.C +++ b/src/aspell.C @@ -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()); } diff --git a/src/aspell_local.h b/src/aspell_local.h index 1b45c70451..f7e840d5f4 100644 --- a/src/aspell_local.h +++ b/src/aspell_local.h @@ -15,8 +15,6 @@ #include "SpellBase.h" -#include "support/docstring.h" - #include @@ -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(); diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index d5e1fdb86d..c001bd27b4 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -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(); } diff --git a/src/frontends/controllers/ControlSpellchecker.h b/src/frontends/controllers/ControlSpellchecker.h index 4f99f6d892..6b19f66175 100644 --- a/src/frontends/controllers/ControlSpellchecker.h +++ b/src/frontends/controllers/ControlSpellchecker.h @@ -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_; } diff --git a/src/frontends/qt4/QSpellchecker.C b/src/frontends/qt4/QSpellchecker.C index a07dbeb98d..30bc8cb4d5 100644 --- a/src/frontends/qt4/QSpellchecker.C +++ b/src/frontends/qt4/QSpellchecker.C @@ -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)); } diff --git a/src/ispell.C b/src/ispell.C index ab7dfcb89c..87613ade36 100644 --- a/src/ispell.C +++ b/src/ispell.C @@ -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); } diff --git a/src/ispell.h b/src/ispell.h index 0fe77a15bc..613c9d208c 100644 --- a/src/ispell.h +++ b/src/ispell.h @@ -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(); diff --git a/src/lyxfind.C b/src/lyxfind.C index 98f30e15d3..93797a6159 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -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(); diff --git a/src/pspell.C b/src/pspell.C index 9d876c1ff8..042161efb7 100644 --- a/src/pspell.C +++ b/src/pspell.C @@ -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(); } diff --git a/src/pspell.h b/src/pspell.h index 7d2cfc14ef..44071dc3e1 100644 --- a/src/pspell.h +++ b/src/pspell.h @@ -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();