]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.cpp
Maintain plain layout for separating paragraphs when switching layouts (#11936)
[lyx.git] / src / support / lstrings.cpp
index 68eabd9d2649c310ecf6324831e19dd324ecd2b0..df356ba9937fa1fcbd93394f482b98d39fbaf356 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);
@@ -406,13 +406,13 @@ bool isHexChar(char_type c)
 
 bool isHex(docstring const & str)
 {
-       int index = 0;
+       size_t index = 0;
 
        if (str.length() > 2 && str[0] == '0' &&
            (str[1] == 'x' || str[1] == 'X'))
                index = 2;
 
-       int const len = str.length();
+       size_t const len = str.length();
 
        for (; index < len; ++index) {
                if (!isHexChar(str[index]))
@@ -422,10 +422,10 @@ bool isHex(docstring const & str)
 }
 
 
-int hexToInt(docstring const & str)
+unsigned int hexToInt(docstring const & str)
 {
        string s = to_ascii(str);
-       int h;
+       unsigned int h;
        sscanf(s.c_str(), "%x", &h);
        return h;
 }
@@ -433,8 +433,8 @@ int hexToInt(docstring const & str)
 
 bool isAscii(docstring const & str)
 {
-       int const len = str.length();
-       for (int i = 0; i < len; ++i)
+       size_t const len = str.length();
+       for (size_t i = 0; i < len; ++i)
                if (str[i] >= 0x80)
                        return false;
        return true;
@@ -443,8 +443,8 @@ bool isAscii(docstring const & str)
 
 bool isAscii(string const & str)
 {
-       int const len = str.length();
-       for (int i = 0; i < len; ++i)
+       size_t const len = str.length();
+       for (size_t i = 0; i < len; ++i)
                if (static_cast<unsigned char>(str[i]) >= 0x80)
                        return false;
        return true;
@@ -890,7 +890,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 +906,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;
@@ -1233,13 +1233,21 @@ docstring const protectArgument(docstring & arg, char const l,
 }
 
 
-bool truncateWithEllipsis(docstring & str, size_t const len)
+bool truncateWithEllipsis(docstring & str, size_t const len, bool const mid)
 {
        if (str.size() <= len)
                return false;
-       str.resize(len);
-       if (len > 0)
-               str[len - 1] = 0x2026;// HORIZONTAL ELLIPSIS
+       if (mid && len > 0) {
+               size_t const hlen = len / 2;
+               docstring suffix = str.substr(str.size() - hlen);
+               str.resize(hlen);
+               str[hlen - 1] = 0x2026;// HORIZONTAL ELLIPSIS
+               str += suffix;
+       } else {
+               str.resize(len);
+               if (len > 0)
+                       str[len - 1] = 0x2026;// HORIZONTAL ELLIPSIS
+       }
        return true;
 }