[LyX/master] Refactoring: move check for match in spellignore() to buffer params.
Stephan Witt
switt at lyx.org
Sun Mar 7 16:40:47 UTC 2021
commit 07122f066b43f9dd41462932894a91aed78201d0
Author: Stephan Witt <switt at lyx.org>
Date: Sun Mar 7 17:46:01 2021 +0100
Refactoring: move check for match in spellignore() to buffer params.
---
src/BufferParams.cpp | 17 +++++++++++++++++
src/BufferParams.h | 1 +
src/Paragraph.cpp | 26 ++++++++------------------
src/Text3.cpp | 12 +-----------
4 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index d4fb384..35c2172 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -616,6 +616,23 @@ IgnoreList const & BufferParams::spellignore() const
}
+bool BufferParams::spellignored(WordLangTuple const & wl) const
+{
+ bool has_item = false;
+ vector<WordLangTuple> il = spellignore();
+ vector<WordLangTuple>::const_iterator it = il.begin();
+ for (; it != il.end(); ++it) {
+ if (it->lang()->code() != wl.lang()->code())
+ continue;
+ if (it->word() == wl.word()) {
+ has_item = true;
+ break;
+ }
+ }
+ return has_item;
+}
+
+
Bullet & BufferParams::temp_bullet(lyx::size_type const index)
{
LASSERT(index < 4, return pimpl_->temp_bullets[0]);
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 10233e6..497332b 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -341,6 +341,7 @@ public:
///
IgnoreList & spellignore();
IgnoreList const & spellignore() const;
+ bool spellignored(WordLangTuple const & wl) const;
/**
* The LyX name of the input encoding for LaTeX. This can be one of
* - \c auto: find out the input encoding from the used languages
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 1faedd6..e4ebf8b 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -464,8 +464,7 @@ public:
pos_type const & first, pos_type const & last,
SpellChecker::Result result,
docstring const & word,
- SkipPositions const & skips,
- vector<WordLangTuple> const & docdict);
+ SkipPositions const & skips);
InsetCode ownerCode() const
{
@@ -4930,8 +4929,7 @@ void Paragraph::Private::markMisspelledWords(
pos_type const & first, pos_type const & last,
SpellChecker::Result result,
docstring const & word,
- SkipPositions const & skips,
- vector<WordLangTuple> const & docdict)
+ SkipPositions const & skips)
{
if (!SpellChecker::misspelled(result)) {
setMisspelled(first, last, SpellChecker::WORD_OK);
@@ -4951,7 +4949,6 @@ void Paragraph::Private::markMisspelledWords(
/// should not happen if speller supports range checks
if (!wlen)
continue;
- docstring const candidate = word.substr(wstart, wlen);
wstart += first + numskipped;
if (snext < wstart) {
/// mark the range of correct spelling
@@ -4961,26 +4958,20 @@ void Paragraph::Private::markMisspelledWords(
}
snext = wstart + wlen;
// Check whether the candidate is in the document's local dict
- vector<WordLangTuple>::const_iterator iit = docdict.begin();
+ WordLangTuple const candidate(word.substr(wstart, wlen), lang);
SpellChecker::Result actresult = result;
- for (; iit != docdict.end(); ++iit) {
- if (iit->lang()->code() != lang->code())
- continue;
- if (iit->word() == candidate) {
- actresult = SpellChecker::WORD_OK;
- break;
- }
- }
+ if (inset_owner_->buffer().params().spellignored(candidate))
+ actresult = SpellChecker::WORD_OK;
numskipped += countSkips(it, et, snext);
/// mark the range of misspelling
setMisspelled(wstart, snext, actresult);
if (actresult == SpellChecker::WORD_OK)
LYXERR(Debug::GUI, "local dictionary word: \"" <<
- candidate << "\" [" <<
+ candidate.word() << "\" [" <<
wstart << ".." << (snext-1) << "]");
else
LYXERR(Debug::GUI, "misspelled word: \"" <<
- candidate << "\" [" <<
+ candidate.word() << "\" [" <<
wstart << ".." << (snext-1) << "]");
++snext;
}
@@ -5013,8 +5004,7 @@ void Paragraph::spellCheck() const
BufferParams const & bparams = d->inset_owner_->buffer().params();
SpellChecker::Result result = !word.empty() ?
speller->check(wl, bparams.spellignore()) : SpellChecker::WORD_OK;
- d->markMisspelledWords(lang, first, last, result, word, skips,
- bparams.spellignore());
+ d->markMisspelledWords(lang, first, last, result, word, skips);
first = ++last;
}
} else {
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 794e962..9ff7150 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -2745,17 +2745,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
}
WordLangTuple wl(word, language);
- bool has_item = false;
- vector<WordLangTuple> il = bv->buffer().params().spellignore();
- vector<WordLangTuple>::const_iterator it = il.begin();
- for (; it != il.end(); ++it) {
- if (it->lang()->code() != wl.lang()->code())
- continue;
- if (it->word() == wl.word()) {
- has_item = true;
- break;
- }
- }
+ bool const has_item = bv->buffer().params().spellignored(wl);
if (!has_item) {
cur.recordUndoBufferParams();
bv->buffer().params().spellignore().push_back(wl);
More information about the lyx-cvs
mailing list