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

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37947 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stephan Witt 2011-03-18 12:50:09 +00:00
parent 85f486f259
commit 291c5c91ec
3 changed files with 16 additions and 8 deletions

View File

@ -179,13 +179,19 @@ Buffer * newUnnamedFile(FileName const & path, string const & prefix,
* are similar but, unfortunately, they seem to have a different * are similar but, unfortunately, they seem to have a different
* notion of what to count. Since nobody ever complained about that, * notion of what to count. Since nobody ever complained about that,
* this proves (again) that any number beats no number ! (JMarc) * 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; int count = 0;
bool inword = false; bool inword = false;
for (DocIterator dit = from ; dit != to && !dit.empty(); ) { for (DocIterator dit = from ; dit != to && !dit.atEnd(); ) {
if (!dit.inTexted()) { if (!dit.inTexted()) {
dit.forwardPos(); dit.forwardPos();
continue; continue;
@ -199,10 +205,11 @@ int countWords(DocIterator const & from, DocIterator const & to)
inword = false; inword = false;
} else if (!par.isDeleted(pos)) { } else if (!par.isDeleted(pos)) {
Inset const * ins = par.getInset(pos); Inset const * ins = par.getInset(pos);
if (ins && !ins->producesOutput()) { if (ins && skipNoOutput && !ins->producesOutput()) {
// skip this inset // skip this inset
++dit.top().pos(); ++dit.top().pos();
if (dit >= to) // stop if end of range was skipped
if (!to.atEnd() && dit >= to)
break; break;
continue; continue;
} }

View File

@ -47,7 +47,8 @@ Buffer * newUnnamedFile(support::FileName const & path,
Buffer * loadIfNeeded(support::FileName const & fname); Buffer * loadIfNeeded(support::FileName const & fname);
/// Count the number of words in the text between these two iterators /// 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 /// Count the number of chars in the text between these two iterators
int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks); int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks);

View File

@ -270,8 +270,8 @@ bool GuiSpellchecker::initialiseParams(string const &)
DocIterator const begin = doc_iterator_begin(&buffer()); DocIterator const begin = doc_iterator_begin(&buffer());
Cursor const & cur = bufferview()->cursor(); Cursor const & cur = bufferview()->cursor();
d->progress_ = countWords(begin, cur); d->progress_ = countWords(begin, cur, false);
d->total_ = d->progress_ + countWords(cur, doc_iterator_end(&buffer())); d->total_ = d->progress_ + countWords(cur, doc_iterator_end(&buffer()), false);
d->count_ = 0; d->count_ = 0;
return true; return true;
} }