diff data/fileio/CSVFormat.cpp @ 1854:bde22957545e

Add support for doubling escapes for quotes in quoted texts in CSV-like formats on import (similar to how we, and the relevant RFC, do escaping on export now)
author Chris Cannam
date Mon, 11 May 2020 14:43:58 +0100
parents 9570ef94eaa3
children 1b8c4ee06f6d
line wrap: on
line diff
--- a/data/fileio/CSVFormat.cpp	Wed May 06 09:08:06 2020 +0100
+++ b/data/fileio/CSVFormat.cpp	Mon May 11 14:43:58 2020 +0100
@@ -135,7 +135,9 @@
         ColumnIncreasing | ColumnNearEmpty;
     
     for (int i = 0; i < cols; ++i) {
-            
+
+        SVDEBUG << "line no " << lineno << ": column " << i << " contains: \"" << list[i] << "\"" << endl;
+        
         while (m_columnQualities.size() <= i) {
             m_columnQualities.push_back(defaultQualities);
             m_prevValues.push_back(0.f);
@@ -157,57 +159,60 @@
         bool signd      = (qualities & ColumnSigned); // also defaults to off
         bool emptyish   = (qualities & ColumnNearEmpty);
 
-        if (lineno > 1 && s.trimmed() != "") {
-            emptyish = false;
-        }
+        if (s.trimmed() != "") {
         
-        float value = 0.f;
+            if (lineno > 1) {
+                emptyish = false;
+            }
+        
+            float value = 0.f;
 
-        //!!! how to take into account headers?
+            //!!! how to take into account headers?
 
-        if (numeric) {
-            value = s.toFloat(&ok);
-            if (!ok) {
-                value = (float)StringBits::stringToDoubleLocaleFree(s, &ok);
-            }
-            if (ok) {
-                if (lineno < 2 && value > 1000.f) {
-                    large = true;
+            if (numeric) {
+                value = s.toFloat(&ok);
+                if (!ok) {
+                    value = (float)StringBits::stringToDoubleLocaleFree(s, &ok);
                 }
-                if (value < 0.f) {
-                    signd = true;
-                }
-                if (value < -1.f || value > 1.f) {
+                if (ok) {
+                    if (lineno < 2 && value > 1000.f) {
+                        large = true;
+                    }
+                    if (value < 0.f) {
+                        signd = true;
+                    }
+                    if (value < -1.f || value > 1.f) {
+                        small = false;
+                    }
+                } else {
+                    numeric = false;
+
+                    // If the column is not numeric, it can't be any of
+                    // these things either
+                    integral = false;
+                    increasing = false;
                     small = false;
-                }
-            } else {
-                numeric = false;
-
-                // If the column is not numeric, it can't be any of
-                // these things either
-                integral = false;
-                increasing = false;
-                small = false;
-                large = false;
-                signd = false;
-            }
-        }
-
-        if (numeric) {
-
-            if (integral) {
-                if (s.contains('.') || s.contains(',')) {
-                    integral = false;
+                    large = false;
+                    signd = false;
                 }
             }
 
-            if (increasing) {
-                if (lineno > 0 && value <= m_prevValues[i]) {
-                    increasing = false;
+            if (numeric) {
+
+                if (integral) {
+                    if (s.contains('.') || s.contains(',')) {
+                        integral = false;
+                    }
                 }
+
+                if (increasing) {
+                    if (lineno > 0 && value <= m_prevValues[i]) {
+                        increasing = false;
+                    }
+                }
+
+                m_prevValues[i] = value;
             }
-
-            m_prevValues[i] = value;
         }
         
         m_columnQualities[i] =