Count words in hyperlink

This commit is contained in:
Richard Kimberly Heck 2021-01-10 01:50:01 -05:00
parent 12bb380941
commit 3f3d769107
5 changed files with 29 additions and 7 deletions

View File

@ -37,7 +37,6 @@
#include "support/FileNameList.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/textutils.h"
#include <algorithm>
#include <climits>
@ -776,15 +775,11 @@ 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);
return pair<int, int>(label.size(), wordCount(label));
}

View File

@ -283,6 +283,13 @@ void InsetHyperlink::validate(LaTeXFeatures & features) const
}
pair<int, int> InsetHyperlink::isWords() const
{
docstring const label = getParam("name");
return pair<int, int>(label.size(), wordCount(label));
}
string InsetHyperlink::contextMenuName() const
{
return "context-hyperlink";

View File

@ -52,6 +52,8 @@ public:
void docbook(XMLStream &, OutputParams const &) const override;
///
docstring xhtml(XMLStream &, OutputParams const &) const override;
///
std::pair<int, int> isWords() const override;
//@}
/// \name Static public methods obligated for InsetCommand derived classes

View File

@ -975,6 +975,21 @@ int count_char(docstring const & str, docstring::value_type chr)
}
int wordCount(docstring const & d)
{
docstring dt = trim(d);
if (dt.empty())
return 0;
int words = 1;
for (auto const & c : dt) {
if (isSpace(c))
words++;
}
return words;
}
int count_bin_chars(string const & str)
{
QString const qstr = toqstr(str).simplified();

View File

@ -204,6 +204,9 @@ int count_char(std::string const & str, char chr);
/// Count all occurrences of char \a chr inside \a str
int count_char(docstring const & str, docstring::value_type chr);
/// get an approximate word count
int wordCount(docstring const &);
/** Count all occurrences of binary chars inside \a str.
It is assumed that \a str is utf-8 encoded and that a binary char
belongs to the unicode class names Zl, Zp, Cc, Cf, Cs, Co, or Cn