mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Count words in hyperlink
This commit is contained in:
parent
12bb380941
commit
3f3d769107
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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";
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user