]> git.lyx.org Git - features.git/commitdiff
get rid of Paragraph::isWord; ignore words with digits in spellchecker
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Nov 2004 14:58:54 +0000 (14:58 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Nov 2004 14:58:54 +0000 (14:58 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9268 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlSpellchecker.C
src/lyxfind.C
src/paragraph.C
src/paragraph.h
src/support/ChangeLog
src/support/textutils.h
src/text.C

index 91d217dadf5749801ec14810834c726cbe070420..6b41ac6c0f76b16082755ea408158848016f435c 100644 (file)
@@ -1,9 +1,18 @@
+2004-11-16  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * 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  <larsbj@gullik.net>
 
        * 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  <larsbj@gullik.net>
index b17637abf5b01f6986170dda541f32c874abe4ae..3bcae6a7524c598ce54eef362467ddf1e2acc507 100644 (file)
@@ -1,3 +1,9 @@
+2004-11-18  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * ControlSpellchecker.C (nextWord): rewrite to skip words
+       containing digits.
+       (isLetter): honor lyxrc.isp_esc_chars
+
 2004-11-18  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * ControlTabular.C (initialiseParams): Compute the active cell
index ffaf47cb4dc861951e37d2e204b419fe5e64b00e..9f8098806af4f0686625bf04a9e8935823d702f6 100644 (file)
@@ -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
index 7592ca73445f4965fec7393ba2001c52638e4472..ee0f53dda032a15bf2e5a8480ccd156e8ea70a2d 100644 (file)
@@ -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;
                }
 
index 516228c5d78424e5ae26295602246fd671c7c94a..d39d43403975ae77404bfc57d963b5c3f1df4c42 100644 (file)
@@ -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);
+       }
 }
 
 
index 82d0732fe32722e57480b4c5da5b0c6df75dba27..2a464d6a27ecbc5d5ebfff03886fd04c0b80b7e4 100644 (file)
@@ -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;
index 5fc0b18e26eaf427417e661fd696265989d46550..52d1d79f78ff7578fdcf4c6b6d8168c33b5a8cb7 100644 (file)
@@ -1,3 +1,7 @@
+2004-11-16  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * textutils.h (isKommaChar): remove
+
 2004-11-16  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * forkedcontr.C (find_pid): simplify and also make pass concept
@@ -13,7 +17,7 @@
 
 2004-11-07  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
-       * Make it clearer where include files are comming from.
+       * Make it clearer where include files are coming from.
 
 2004-11-06  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
index f6e1cc2e67041e0cf65653586242e92ec9777151..19867e79edbc85829ac36c76f3f6e6ee829d4a6d 100644 (file)
@@ -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)
index c6dcac79284b215805bd18b5494b701cf429e3ac..6e0d6ceaee49cf995a902559ce34da6570206d54 100644 (file)
@@ -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();
 }