]> git.lyx.org Git - lyx.git/commitdiff
Count words in hyperlink
authorRichard Kimberly Heck <rikiheck@lyx.org>
Sun, 10 Jan 2021 06:50:01 +0000 (01:50 -0500)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Sun, 10 Jan 2021 06:54:40 +0000 (01:54 -0500)
src/insets/InsetCitation.cpp
src/insets/InsetHyperlink.cpp
src/insets/InsetHyperlink.h
src/support/lstrings.cpp
src/support/lstrings.h

index 6672ea1260266bdb2ecd361393ff6daa5212b06d..1cc145ab816e43023fdca350f5fd84d37038189a 100644 (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));
 }
 
 
index 3801f4de9025ba3a16b6b972948af511e1cc402a..3f1131c4ad3a86cb12a882a909026e5f89e61e52 100644 (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";
index 999e3753c0434f73e3c6798e7dbe7cf889f3f267..974f2f431af5bfd4727e8501fd1c0911f4835593 100644 (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
index b85307f5b2fe91787cd984406bd3526e05be7017..351c9775cc82a4817238ca9e89da8009bf885229 100644 (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();
index b4f99f81567e3249110273abe2f912d05e9b810c..3d42bb60316f968c345b1b7ef91169bd768ef66e 100644 (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