We use Inset::producesOutput to skip things like notes and inactive
branches.

	* buffer_funcs.cpp (countWords): align code style with countChars;
	skip insets for which producesOutput() is false.
	(countChars): honor Inset::producesOutput.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30242 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2009-06-23 09:46:48 +00:00
parent 8a421dcd37
commit 01b290e2dd

View File

@ -168,42 +168,68 @@ Buffer * newUnnamedFile(string const & templatename, FileName const & path)
return newFile(filename.absFilename(), templatename, false);
}
/*
* FIXME : merge with countChars. The structures of the two functions
* 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)
*/
int countWords(DocIterator const & from, DocIterator const & to)
{
int count = 0;
bool inword = false;
for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
// FIXME: use Paragraph::isWordSeparator
for (DocIterator dit = from ; dit != to ; ) {
if (!dit.inTexted()) {
dit.forwardPos();
continue;
}
Paragraph const & par = dit.paragraph();
pos_type const pos = dit.pos();
// Copied and adapted from isWordSeparator() in Paragraph
if (dit.inTexted()
&& dit.pos() != dit.lastpos()
&& !dit.paragraph().isWordSeparator(dit.pos())
&& !dit.paragraph().isDeleted(dit.pos())) {
if (!inword) {
if (pos != dit.lastpos() && !par.isDeleted(pos)) {
Inset const * ins = par.getInset(pos);
if (ins && !ins->producesOutput()) {
//skip this inset
++dit.top().pos();
continue;
}
if (par.isWordSeparator(pos))
inword = false;
else if (!inword) {
++count;
inword = true;
}
} else if (inword)
inword = false;
}
dit.forwardPos();
}
return count;
}
int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks)
int countChars(DocIterator const & from, DocIterator const & to,
bool with_blanks)
{
int chars = 0;
int blanks = 0;
for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
if (!dit.inTexted()) continue;
for (DocIterator dit = from ; dit != to ; ) {
if (!dit.inTexted()) {
dit.forwardPos();
continue;
}
Paragraph const & par = dit.paragraph();
pos_type const pos = dit.pos();
if (pos != dit.lastpos() && !par.isDeleted(pos)) {
if (Inset const * ins = par.getInset(pos)) {
if (!ins->producesOutput()) {
//skip this inset
++dit.top().pos();
continue;
}
if (ins->isLetter())
++chars;
else if (with_blanks && ins->isSpace())
@ -216,6 +242,7 @@ int countChars(DocIterator const & from, DocIterator const & to, bool with_blank
++blanks;
}
}
dit.forwardPos();
}
return chars + blanks;