]> git.lyx.org Git - features.git/blobdiff - src/support/lstrings.cpp
Handle multiple spaces at row break
[features.git] / src / support / lstrings.cpp
index b85307f5b2fe91787cd984406bd3526e05be7017..d5b6dea588f10e40d378576f0be08270d444f29e 100644 (file)
@@ -189,6 +189,13 @@ bool isDigitASCII(char_type c)
        return '0' <= c && c <= '9';
 }
 
+bool isNumberChar(char_type c)
+{
+       if (c > ucs4_max)
+               // outside the UCS4 range
+               return false;
+       return ucs4_to_qchar(c).isNumber();
+}
 
 bool isAlnumASCII(char_type c)
 {
@@ -975,6 +982,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();
@@ -1480,6 +1502,20 @@ string from_percent_encoding(string const & in)
 }
 
 
+int countExpanders(docstring const & str)
+{
+       // Numbers of characters that are expanded by inter-word spacing.  These
+       // characters are spaces, except for characters 09-0D which are treated
+       // specially.  (From a combination of testing with the notepad found in qt's
+       // examples, and reading the source code.)
+       int nexp = 0;
+       for (char_type c : str)
+               if (c > 0x0d && isSpace(c))
+                       ++nexp;
+       return nexp;
+}
+
+
 docstring bformat(docstring const & fmt, int arg1)
 {
        LATTEST(contains(fmt, from_ascii("%1$d")));