changeset 1300:4a2bc07ec0fb 3.0-integration

Make CSV feature writer produce the same output with Qt 5.6 and 5.7+
author Chris Cannam
date Fri, 25 Nov 2016 17:33:44 +0000
parents 838a45cff62d
children 9d443c13c5d1
files transform/CSVFeatureWriter.cpp
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/transform/CSVFeatureWriter.cpp	Fri Nov 25 17:33:12 2016 +0000
+++ b/transform/CSVFeatureWriter.cpp	Fri Nov 25 17:33:44 2016 +0000
@@ -276,7 +276,20 @@
     }
     
     for (unsigned int j = 0; j < f.values.size(); ++j) {
-        stream << m_separator << QString("%1").arg(f.values[j], 0, 'g', m_digits);
+
+        QString number = QString("%1").arg(f.values[j], 0, 'g', m_digits);
+
+        // Qt pre-5.6 zero pads single-digit exponents to two digits;
+        // Qt 5.7+ doesn't by default. But we want both to produce the
+        // same output. Getting the new behaviour from standard APIs
+        // in Qt 5.6 isn't possible I think; getting the old behaviour
+        // from Qt 5.7 is possible but fiddly, involving setting up an
+        // appropriate locale and using the %L specifier. We could
+        // doubtless do it with sprintf but Qt is a known quantity at
+        // this point. Let's just convert the old format to the new.
+        number.replace("e-0", "e-");
+        
+        stream << m_separator << number;
     }
     
     if (f.label != "") {