Fix bug #5972: Count words in citations (approximately).

This commit is contained in:
Richard Kimberly Heck 2021-01-10 01:43:34 -05:00
parent 50b99f810f
commit 12bb380941
5 changed files with 26 additions and 2 deletions

View File

@ -5365,6 +5365,12 @@ void Buffer::Impl::updateStatistics(DocIterator & from, DocIterator & to, bool s
}
else if (ins && ins->isSpace())
++blank_count_;
else if (ins) {
pair<int, int> words = ins->isWords();
char_count_ += words.first;
word_count_ += words.second;
inword = false;
}
else {
char_type const c = par.getChar(pos);
if (isPrintableNonspace(c))

View File

@ -1056,6 +1056,7 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
setDesktopFileName(lyx_package);
#endif
// FIXME Deprecated. Should use QRandomGenerator since 5.10
qsrand(QDateTime::currentDateTime().toTime_t());
// Install LyX translator for missing Qt translations

View File

@ -466,6 +466,9 @@ public:
/// is this equivalent to a space (which is BTW different from
/// a line separator)?
virtual bool isSpace() const { return false; }
/// returns chars, words if the inset is equivalent to such, otherwise
/// (0,0), which should be interpreted as 'false'
virtual std::pair<int, int> isWords() const { return std::pair<int,int>(0, 0); }
/// does this inset try to use all available space (like \\hfill does)?
virtual bool isHfill() const { return false; }

View File

@ -37,6 +37,7 @@
#include "support/FileNameList.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/textutils.h"
#include <algorithm>
#include <climits>
@ -594,7 +595,7 @@ int InsetCitation::plaintext(odocstringstream & os,
if (cmd == "nocite")
return 0;
docstring const label = generateLabel(false);
docstring const label = generateLabel();
os << label;
return label.size();
}
@ -658,7 +659,7 @@ docstring InsetCitation::xhtml(XMLStream & xs, OutputParams const &) const
void InsetCitation::toString(odocstream & os) const
{
odocstringstream ods;
plaintext(ods, OutputParams(0));
plaintext(ods, OutputParams(nullptr));
os << ods.str();
}
@ -775,6 +776,17 @@ void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
os << "}";
}
pair<int, int> InsetCitation::isWords() const
{
docstring const label = generateLabel(false);
int words = 1;
for (auto const & c : label) {
if (lyx::isSpace(c))
words++;
}
return pair<int, int>(label.size(), words);
}
string InsetCitation::contextMenuName() const
{

View File

@ -101,6 +101,8 @@ public:
bool openCitationPossible() const;
/// search and open citation source
void openCitation();
///
std::pair<int, int> isWords() const override;
private:
/// tries to make a pretty label and makes a basic one if not