From 020972b7f9bf54b333ff4d6a865d76d51f08d6b4 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 18 Nov 2004 14:58:54 +0000 Subject: [PATCH] get rid of Paragraph::isWord; ignore words with digits in spellchecker git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9268 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 11 +++- src/frontends/controllers/ChangeLog | 6 +++ .../controllers/ControlSpellchecker.C | 54 +++++++++++++------ src/lyxfind.C | 4 +- src/paragraph.C | 28 ++-------- src/paragraph.h | 7 +-- src/support/ChangeLog | 6 ++- src/support/textutils.h | 30 ----------- src/text.C | 18 +++---- 9 files changed, 75 insertions(+), 89 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 91d217dadf..6b41ac6c0f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,9 +1,18 @@ +2004-11-16 Jean-Marc Lasgouttes + + * paragraph.C (isLetter): remove special spellchecker-related + code; return true also for digits + (isWord, isKomma): remove + + * text.C (cursorRightOneWord, cursorLeftOneWord, getWord): + * lyxfind.C (MatchString()): use isLetter instead of isWord + 2004-11-17 Lars Gullik Bjonnes * pariterator.h (operatir=): comment out un-implemented member function. - * paragraph.h: resolv ambiguity found by gcc 4.0 with the use of a + * paragraph.h: resolve ambiguity found by gcc 4.0 with the use of a static cast. 2004-11-17 Lars Gullik Bjonnes diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index b17637abf5..3bcae6a752 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,9 @@ +2004-11-18 Jean-Marc Lasgouttes + + * ControlSpellchecker.C (nextWord): rewrite to skip words + containing digits. + (isLetter): honor lyxrc.isp_esc_chars + 2004-11-18 Georg Baum * ControlTabular.C (initialiseParams): Compute the active cell diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index ffaf47cb4d..9f8098806a 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -32,6 +32,7 @@ #endif #endif +#include "support/textutils.h" #include "support/tostr.h" #include "frontends/Alert.h" @@ -44,6 +45,7 @@ using std::string; namespace lyx { using support::bformat; +using support::contains; namespace frontend { @@ -121,7 +123,10 @@ bool isLetter(DocIterator const & cur) return cur.inTexted() && cur.inset().allowSpellCheck() && cur.pos() != cur.lastpos() - && cur.paragraph().isLetter(cur.pos()) + && (cur.paragraph().isLetter(cur.pos()) + // We want to pass the ' and escape chars to ispell + || contains(lyxrc.isp_esc_chars + '\'', + cur.paragraph().getChar(cur.pos()))) && !isDeletedText(cur.paragraph(), cur.pos()); } @@ -129,25 +134,40 @@ bool isLetter(DocIterator const & cur) WordLangTuple nextWord(DocIterator & cur, ptrdiff_t & progress, BufferParams & bp) { - // skip until we have real text (will jump paragraphs) - for (; cur.size() && !isLetter(cur); cur.forwardPos()); + bool inword = false; + bool ignoreword = false; + string word, lang_code; + + while(cur.size()) { + if (isLetter(cur)) { + if (!inword) { + inword = true; + ignoreword = false; + word.clear(); + lang_code = cur.paragraph().getFontSettings(bp, cur.pos()).language()->code(); + } + // Insets like optional hyphens and ligature + // break are part of a word. + if (!cur.paragraph().isInset(cur.pos())) { + Paragraph::value_type const c = + cur.paragraph().getChar(cur.pos()); + word += c; + if (IsDigit(c)) + ignoreword = true; + } + } else { // !isLetter(cur) + if (inword) + if (!ignoreword) + return WordLangTuple(word, lang_code); + else + inword = false; + } + + cur.forwardPos(); ++progress; - - // hit end - if (cur.empty()) - return WordLangTuple(string(), string()); - - string lang_code = cur.paragraph(). - getFontSettings(bp, cur.pos()).language()->code(); - string str; - // and find the end of the word (insets like optional hyphens - // and ligature break are part of a word) - for (; cur && isLetter(cur); cur.forwardPos(), ++progress) { - if (!cur.paragraph().isInset(cur.pos())) - str += cur.paragraph().getChar(cur.pos()); } - return WordLangTuple(str, lang_code); + return WordLangTuple(string(), string()); } } // namespace anon diff --git a/src/lyxfind.C b/src/lyxfind.C index 7592ca7344..ee0f53dda0 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -85,10 +85,10 @@ public: // if necessary, check whether string matches word if (mw) { - if (pos > 0 && par.isWord(pos - 1)) + if (pos > 0 && par.isLetter(pos - 1)) return false; if (pos + lyx::pos_type(size) < parsize - && par.isWord(pos + size)); + && par.isLetter(pos + size)); return false; } diff --git a/src/paragraph.C b/src/paragraph.C index 516228c5d7..d39d434039 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -53,7 +53,6 @@ using lyx::pos_type; -using lyx::support::contains; using lyx::support::subst; using std::distance; @@ -1510,34 +1509,15 @@ bool Paragraph::isLineSeparator(pos_type pos) const } -bool Paragraph::isKomma(pos_type pos) const -{ - return IsKommaChar(getChar(pos)); -} - - /// Used by the spellchecker bool Paragraph::isLetter(pos_type pos) const -{ - value_type const c = getChar(pos); - if (IsLetterChar(c)) - return true; - if (isInset(pos)) - return getInset(pos)->isLetter(); - // We want to pass the ' and escape chars to ispell - string const extra = lyxrc.isp_esc_chars + '\''; - return contains(extra, c); -} - - -bool Paragraph::isWord(pos_type pos) const { if (isInset(pos)) return getInset(pos)->isLetter(); - value_type const c = getChar(pos); - return !(IsSeparatorChar(c) - || IsKommaChar(c) - || IsInsetChar(c)); + else { + value_type const c = getChar(pos); + return IsLetterChar(c) || IsDigit(c); + } } diff --git a/src/paragraph.h b/src/paragraph.h index 82d0732fe3..2a464d6a27 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -335,12 +335,9 @@ public: bool isSeparator(lyx::pos_type pos) const; /// bool isLineSeparator(lyx::pos_type pos) const; - /// - bool isKomma(lyx::pos_type pos) const; - /// Used by the spellchecker + /// True if the character/inset at this point can be part of a word + // Note that digits in particular are considered as letters bool isLetter(lyx::pos_type pos) const; - /// - bool isWord(lyx::pos_type pos) const; /// returns -1 if inset not found int getPositionOfInset(InsetBase const * inset) const; diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 5fc0b18e26..52d1d79f78 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,7 @@ +2004-11-16 Jean-Marc Lasgouttes + + * textutils.h (isKommaChar): remove + 2004-11-16 Lars Gullik Bjonnes * forkedcontr.C (find_pid): simplify and also make pass concept @@ -13,7 +17,7 @@ 2004-11-07 Lars Gullik Bjonnes - * Make it clearer where include files are comming from. + * Make it clearer where include files are coming from. 2004-11-06 Lars Gullik Bjonnes diff --git a/src/support/textutils.h b/src/support/textutils.h index f6e1cc2e67..19867e79ed 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -31,36 +31,6 @@ bool IsLineSeparatorChar(char c) } -/// return true if the char is "punctuation" -inline -bool IsKommaChar(char c) -{ - return c == ',' - || c == '(' - || c == ')' - || c == '[' - || c == ']' - || c == '{' - || c == '}' - || c == ';' - || c == '.' - || c == ':' - || c == '-' - || c == '?' - || c == '!' - || c == '&' - || c == '@' - || c == '+' - || c == '-' - || c == '~' - || c == '#' - || c == '%' - || c == '^' - || c == '/' - || c == '\\'; -} - - /// return true if a char is alphabetical (including accented chars) inline bool IsLetterChar(unsigned char c) diff --git a/src/text.C b/src/text.C index c6dcac7928..6e0d6ceaee 100644 --- a/src/text.C +++ b/src/text.C @@ -1355,10 +1355,10 @@ void LyXText::cursorRightOneWord(LCursor & cur) } else { // Skip through initial nonword stuff. // Treat floats and insets as words. - while (cur.pos() != cur.lastpos() && !cur.paragraph().isWord(cur.pos())) + while (cur.pos() != cur.lastpos() && !cur.paragraph().isLetter(cur.pos())) ++cur.pos(); // Advance through word. - while (cur.pos() != cur.lastpos() && cur.paragraph().isWord(cur.pos())) + while (cur.pos() != cur.lastpos() && cur.paragraph().isLetter(cur.pos())) ++cur.pos(); } setCursor(cur, cur.par(), cur.pos()); @@ -1374,10 +1374,10 @@ void LyXText::cursorLeftOneWord(LCursor & cur) } else { // Skip through initial nonword stuff. // Treat floats and insets as words. - while (cur.pos() != 0 && !cur.paragraph().isWord(cur.pos() - 1)) + while (cur.pos() != 0 && !cur.paragraph().isLetter(cur.pos() - 1)) --cur.pos(); // Advance through word. - while (cur.pos() != 0 && cur.paragraph().isWord(cur.pos() - 1)) + while (cur.pos() != 0 && cur.paragraph().isLetter(cur.pos() - 1)) --cur.pos(); } setCursor(cur, cur.par(), cur.pos()); @@ -1797,8 +1797,8 @@ void LyXText::getWord(CursorSlice & from, CursorSlice & to, switch (loc) { case lyx::WHOLE_WORD_STRICT: if (from.pos() == 0 || from.pos() == from_par.size() - || !from_par.isWord(from.pos()) - || !from_par.isWord(from.pos() - 1)) { + || !from_par.isLetter(from.pos()) + || !from_par.isLetter(from.pos() - 1)) { to = from; return; } @@ -1806,13 +1806,13 @@ void LyXText::getWord(CursorSlice & from, CursorSlice & to, case lyx::WHOLE_WORD: // If we are already at the beginning of a word, do nothing - if (!from.pos() || !from_par.isWord(from.pos() - 1)) + if (!from.pos() || !from_par.isLetter(from.pos() - 1)) break; // no break here, we go to the next case lyx::PREVIOUS_WORD: // always move the cursor to the beginning of previous word - while (from.pos() && from_par.isWord(from.pos() - 1)) + while (from.pos() && from_par.isLetter(from.pos() - 1)) --from.pos(); break; case lyx::NEXT_WORD: @@ -1825,7 +1825,7 @@ void LyXText::getWord(CursorSlice & from, CursorSlice & to, } to = from; Paragraph & to_par = pars_[to.par()]; - while (to.pos() < to_par.size() && to_par.isWord(to.pos())) + while (to.pos() < to_par.size() && to_par.isLetter(to.pos())) ++to.pos(); } -- 2.39.2