summaryrefslogtreecommitdiff
path: root/source/fud_csv.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/fud_csv.cpp')
-rw-r--r--source/fud_csv.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/source/fud_csv.cpp b/source/fud_csv.cpp
index bcef925..260a4ff 100644
--- a/source/fud_csv.cpp
+++ b/source/fud_csv.cpp
@@ -144,7 +144,10 @@ FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, size_t maxE
static_cast<void>(csv);
constexpr size_t BufferSize = 256;
SimpleStackAllocator<BufferSize> stackAllocator{};
- auto bufferedFile{BufferedRegularFile::make(std::move(file), TextBuffer{stackAllocator})};
+ TextBuffer textBuffer{stackAllocator};
+ auto resizeResult = textBuffer.resize(BufferSize);
+ fudAssert(resizeResult == FudStatus::Success);
+ auto bufferedFile{BufferedRegularFile::make(std::move(file), std::move(textBuffer))};
return parseFromBufferedFile(csv, bufferedFile, maxExtraAttempts);
}
@@ -222,6 +225,7 @@ DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t
bool sawQuote{false};
bool addToSize{};
size_t numColumns{0};
+ size_t lineLength{0};
while (not endOfLine) {
addToSize = false;
@@ -239,7 +243,7 @@ DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t
}
if (maybeNewline and utf8Char != Utf8{Ascii{lineEnding[1]}}) {
- rawSize += 2;
+ lineLength += 2;
maybeNewline = false;
} else if (inQuote and utf8Char == csv.quoteCharacter) {
inQuote = false;
@@ -270,7 +274,7 @@ DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t
}
if (addToSize and numColumns < csv.numColumns) {
- rawSize += utf8Char.size();
+ lineLength += utf8Char.size();
}
if (numColumns > csv.numColumns and csv.strictColumns) {
@@ -279,6 +283,11 @@ DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t
}
}
+ rawSize += lineLength;
+ if (numColumns > 0 && lineLength == 0) {
+ numColumns = 0;
+ }
+
if (numColumns == 0) {
readResult.status = FudStatus::Empty;
return readResult;
@@ -297,6 +306,11 @@ FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSi
{
static_cast<void>(rawSize);
+ auto flushResult = file.flush();
+ if (flushResult.status != FudStatus::Success) {
+ return flushResult.status;
+ }
+
auto seekStatus = file.seekStart();
if (seekStatus != FudStatus::Success) {
return seekStatus;