]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.cpp
Let paragraph::requestSpellcheck() consider contained insets
[lyx.git] / src / support / lstrings.cpp
index 88aa1e0de098bed4ad1d3d3d02e8530001dcbc4f..351c9775cc82a4817238ca9e89da8009bf885229 100644 (file)
@@ -146,7 +146,7 @@ bool isSpace(char_type c)
 {
        if (!is_utf16(c)) {
                // assume that no non-utf16 character is a space
-               // c outside the UCS4 range is catched as well
+               // c outside the UCS4 range is caught as well
                return false;
        }
        QChar const qc = ucs4_to_qchar(c);
@@ -158,19 +158,19 @@ bool isNumber(char_type c)
 {
        if (!is_utf16(c))
                // assume that no non-utf16 character is a numeral
-               // c outside the UCS4 range is catched as well
+               // c outside the UCS4 range is caught as well
                return false;
        return ucs4_to_qchar(c).isNumber();
 }
 
 
-bool isEuropeanNumberSeparator(char_type c)
+bool isCommonNumberSeparator(char_type c)
 {
        if (!is_utf16(c))
                // assume that no non-utf16 character is a numeral
-               // c outside the UCS4 range is catched as well
+               // c outside the UCS4 range is caught as well
                return false;
-       return ucs4_to_qchar(c).direction() == QChar::DirES;
+       return ucs4_to_qchar(c).direction() == QChar::DirCS;
 }
 
 
@@ -178,7 +178,7 @@ bool isEuropeanNumberTerminator(char_type c)
 {
        if (!is_utf16(c))
                // assume that no non-utf16 character is a numeral
-               // c outside the UCS4 range is catched as well
+               // c outside the UCS4 range is caught as well
                return false;
        return ucs4_to_qchar(c).direction() == QChar::DirET;
 }
@@ -206,7 +206,7 @@ bool isOpenPunctuation(char_type c)
 {
        if (!is_utf16(c)) {
                // assume that no non-utf16 character is an op
-               // c outside the UCS4 range is catched as well
+               // c outside the UCS4 range is caught as well
                return false;
        }
        QChar const qc = ucs4_to_qchar(c);
@@ -543,6 +543,14 @@ docstring const uppercase(docstring const & a)
 }
 
 
+docstring capitalize(docstring const & s) {
+       docstring ret = s;
+       char_type t = uppercase(ret[0]);
+       ret[0] = t;
+       return ret;
+}
+
+
 string const ascii_lowercase(string const & a)
 {
        string tmp(a);
@@ -890,7 +898,7 @@ String const subst_string(String const & a,
        size_t const olen = oldstr.length();
        while ((i = lstr.find(oldstr, i)) != string::npos) {
                lstr.replace(i, olen, newstr);
-               i += newstr.length(); // We need to be sure that we dont
+               i += newstr.length(); // We need to be sure that we don't
                // use the same i over and over again.
        }
        return lstr;
@@ -906,7 +914,7 @@ docstring const subst_string(docstring const & a,
        size_t const olen = oldstr.length();
        while ((i = lstr.find(oldstr, i)) != string::npos) {
                lstr.replace(i, olen, newstr);
-               i += newstr.length(); // We need to be sure that we dont
+               i += newstr.length(); // We need to be sure that we don't
                // use the same i over and over again.
        }
        return lstr;
@@ -967,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();
@@ -1197,8 +1220,7 @@ docstring const escape(docstring const & lab)
        char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
                                   '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        docstring enc;
-       for (size_t i = 0; i < lab.length(); ++i) {
-               char_type c = lab[i];
+       for (char_type const c : lab) {
                if (c >= 128 || c == '=' || c == '%' || c == '#' || c == '$'
                    || c == '}' || c == '{' || c == ']' || c == '[' || c == '&'
                    || c == '\\') {
@@ -1447,8 +1469,8 @@ std::string formatFPNumber(double x)
        os << std::fixed;
        // Prevent outputs of 23.4200000000000017 but output small numbers
        // with at least 6 significant digits.
-       double const logarithm = log10(fabs(x));
-       os << std::setprecision(max(6 - iround(logarithm), 0)) << x;
+       int const precision = (x == 0.0) ? 0 : max(6 - iround(log10(fabs(x))), 0);
+       os << std::setprecision(precision) << x;
        string result = os.str();
        if (result.find('.') != string::npos) {
                result = rtrim(result, "0");
@@ -1545,11 +1567,7 @@ docstring bformat(docstring const & fmt, docstring const & arg1, int arg2)
 
 docstring bformat(docstring const & fmt, char const * arg1, docstring const & arg2)
 {
-       LATTEST(contains(fmt, from_ascii("%1$s")));
-       LATTEST(contains(fmt, from_ascii("%2$s")));
-       docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
-       str = subst(str, from_ascii("%2$s"), arg2);
-       return subst(str, from_ascii("%%"), from_ascii("%"));
+       return bformat(fmt, from_ascii(arg1), arg2);
 }