mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
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
This commit is contained in:
parent
8193ac607b
commit
26460b39ee
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -40,9 +40,9 @@ void SpellBase::accept(WordLangTuple const &)
|
||||
{}
|
||||
|
||||
|
||||
string const SpellBase::nextMiss()
|
||||
docstring const SpellBase::nextMiss()
|
||||
{
|
||||
return string();
|
||||
return docstring();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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_;
|
||||
};
|
||||
|
18
src/aspell.C
18
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());
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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_; }
|
||||
|
@ -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));
|
||||
}
|
||||
|
24
src/ispell.C
24
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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
19
src/pspell.C
19
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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user