From 987f57910a9afec37b9859976e411096fe9629a1 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Tue, 15 Aug 2023 14:44:53 +0100 Subject: [PATCH] Make TabularData::contentIdentityOf identify more aggressively --- source/shared/loading/tabulardata.cpp | 33 +++++++++++++-------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/source/shared/loading/tabulardata.cpp b/source/shared/loading/tabulardata.cpp index 6911cb6d6..b82ed7d5f 100644 --- a/source/shared/loading/tabulardata.cpp +++ b/source/shared/loading/tabulardata.cpp @@ -248,6 +248,7 @@ QString TabularData::contentIdentityOf(const QUrl& url) const int maxLines = 50; int numLinesScanned = 0; + std::map counts; std::istream* is = nullptr; do @@ -256,7 +257,6 @@ QString TabularData::contentIdentityOf(const QUrl& url) is = &u::getline(file, line); - std::map counts; bool inQuotes = false; for(auto character : line) @@ -278,25 +278,24 @@ QString TabularData::contentIdentityOf(const QUrl& url) } } - if(!counts.empty()) - { - auto maxCount = std::max_element(counts.begin(), counts.end(), - [](const auto& a, const auto& b) { return a.second < b.second; }); + numLinesScanned++; + } while(!is->fail() && !is->eof() && + numLinesScanned < maxLines); - auto character = maxCount->first; + if(!counts.empty()) + { + auto maxCount = std::max_element(counts.begin(), counts.end(), + [](const auto& a, const auto& b) { return a.second < b.second; }); - switch(character) - { - case ',': identity = u"CSV"_s; break; - case ';': identity = u"SSV"_s; break; - case '\t': identity = u"TSV"_s; break; - } - } + auto character = maxCount->first; - numLinesScanned++; - } while(identity.isEmpty() && - !is->fail() && !is->eof() && - numLinesScanned < maxLines); + switch(character) + { + case ',': identity = u"CSV"_s; break; + case ';': identity = u"SSV"_s; break; + case '\t': identity = u"TSV"_s; break; + } + } return identity; }