Author: switt
Date: Fri Mar 18 13:50:09 2011
New Revision: 37947
URL: http://www.lyx.org/trac/changeset/37947

Log:
#7357 correct the numbers by introducing two modes of word count

Modified:
   lyx-devel/trunk/src/buffer_funcs.cpp
   lyx-devel/trunk/src/buffer_funcs.h
   lyx-devel/trunk/src/frontends/qt4/GuiSpellchecker.cpp

Modified: lyx-devel/trunk/src/buffer_funcs.cpp
==============================================================================
--- lyx-devel/trunk/src/buffer_funcs.cpp        Fri Mar 18 10:17:09 2011        
(r37946)
+++ lyx-devel/trunk/src/buffer_funcs.cpp        Fri Mar 18 13:50:09 2011        
(r37947)
@@ -179,13 +179,19 @@
  * are similar but, unfortunately, they seem to have a different
  * notion of what to count. Since nobody ever complained about that,
  * this proves (again) that any number beats no number ! (JMarc)
+ * We have two use cases:
+ * 1. Count the words of the given range for document statistics
+ * - ignore inset content without output. (skipNoOutput == true)
+ * 2. Count the words to present a progress bar for the spell checker
+ * - has to count whole content. (skipNoOutput == false)
  */
-int countWords(DocIterator const & from, DocIterator const & to)
+int countWords(DocIterator const & from, DocIterator const & to,
+                          bool skipNoOutput)
 {
        int count = 0;
        bool inword = false;
        
-       for (DocIterator dit = from ; dit != to && !dit.empty(); ) {
+       for (DocIterator dit = from ; dit != to && !dit.atEnd(); ) {
                if (!dit.inTexted()) {
                        dit.forwardPos();
                        continue;
@@ -199,10 +205,11 @@
                        inword = false;
                } else if (!par.isDeleted(pos)) {
                        Inset const * ins = par.getInset(pos);
-                       if (ins && !ins->producesOutput()) {
-                               //skip this inset
+                       if (ins && skipNoOutput && !ins->producesOutput()) {
+                               // skip this inset
                                ++dit.top().pos();
-                               if (dit >= to)
+                               // stop if end of range was skipped
+                               if (!to.atEnd() && dit >= to)
                                        break;
                                continue;
                        }

Modified: lyx-devel/trunk/src/buffer_funcs.h
==============================================================================
--- lyx-devel/trunk/src/buffer_funcs.h  Fri Mar 18 10:17:09 2011        (r37946)
+++ lyx-devel/trunk/src/buffer_funcs.h  Fri Mar 18 13:50:09 2011        (r37947)
@@ -47,7 +47,8 @@
 Buffer * loadIfNeeded(support::FileName const & fname);
 
 /// Count the number of words in the text between these two iterators
-int countWords(DocIterator const & from, DocIterator const & to);
+int countWords(DocIterator const & from, DocIterator const & to,
+               bool skipNoOutput = true);
 
 /// Count the number of chars in the text between these two iterators
 int countChars(DocIterator const & from, DocIterator const & to, bool 
with_blanks);

Modified: lyx-devel/trunk/src/frontends/qt4/GuiSpellchecker.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiSpellchecker.cpp       Fri Mar 18 
10:17:09 2011        (r37946)
+++ lyx-devel/trunk/src/frontends/qt4/GuiSpellchecker.cpp       Fri Mar 18 
13:50:09 2011        (r37947)
@@ -270,8 +270,8 @@
 
        DocIterator const begin = doc_iterator_begin(&buffer());
        Cursor const & cur = bufferview()->cursor();
-       d->progress_ = countWords(begin, cur);
-       d->total_ = d->progress_ + countWords(cur, doc_iterator_end(&buffer()));
+       d->progress_ = countWords(begin, cur, false);
+       d->total_ = d->progress_ + countWords(cur, doc_iterator_end(&buffer()), 
false);
        d->count_ = 0;
        return true;
 }

Reply via email to