]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.cpp
Fix bugs #6078 and #9364
[lyx.git] / src / support / lstrings.cpp
index 6faf1a4fc3fd25838adb3b8c52c390315f569578..5e68b755d06868cd0657736789a63d0e81a10de0 100644 (file)
@@ -1074,18 +1074,20 @@ String const doSplit(String const & a, String & piece, Char delim)
        size_t i = a.find(delim);
        if (i == a.length() - 1) {
                piece = a.substr(0, i);
-       } else if (i != String::npos) {
-               piece = a.substr(0, i);
-               tmp = a.substr(i + 1);
        } else if (i == 0) {
                piece.erase();
                tmp = a.substr(i + 1);
+       } else if (i != String::npos) {
+               piece = a.substr(0, i);
+               tmp = a.substr(i + 1);
        } else {
                piece = a;
        }
        return tmp;
 }
 
+
+// FIXME: why is this specialization needed?
 template<typename Char> inline
 docstring const doSplit(docstring const & a, docstring & piece, Char delim)
 {
@@ -1093,12 +1095,12 @@ docstring const doSplit(docstring const & a, docstring & piece, Char delim)
        size_t i = a.find(delim);
        if (i == a.length() - 1) {
                piece = a.substr(0, i);
-       } else if (i != docstring::npos) {
-               piece = a.substr(0, i);
-               tmp = a.substr(i + 1);
        } else if (i == 0) {
                piece.erase();
                tmp = a.substr(i + 1);
+       } else if (i != docstring::npos) {
+               piece = a.substr(0, i);
+               tmp = a.substr(i + 1);
        } else {
                piece = a;
        }
@@ -1407,11 +1409,7 @@ std::string formatFPNumber(double x)
        os << std::fixed;
        // Prevent outputs of 23.4200000000000017 but output small numbers
        // with at least 6 significant digits.
-       bool const neg = x < 0;
-       // Treat all doubles as positive for the formatting
-       if (neg)
-               x = -x;
-       double const logarithm = log10(x);
+       double const logarithm = log10(fabs(x));
        os << std::setprecision(max(6 - static_cast<int>(round(logarithm)), 0)) << x;
        string result = os.str();
        if (result.find('.') != string::npos) {
@@ -1419,9 +1417,6 @@ std::string formatFPNumber(double x)
                if (result[result.length()-1] == '.')
                        result = rtrim(result, ".");
        }
-       // Re-add negativity
-       if (neg)
-               result = "-" + result;
        return result;
 }