From d5a174a6d4f8be5e7cffe7c2adbb8db23b578f56 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 2 Jan 2025 18:49:56 -0600 Subject: Fixing errors in Vector. --- source/fud_csv.cpp | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) (limited to 'source/fud_csv.cpp') diff --git a/source/fud_csv.cpp b/source/fud_csv.cpp index e1ecf72..bcef925 100644 --- a/source/fud_csv.cpp +++ b/source/fud_csv.cpp @@ -17,8 +17,6 @@ #include "fud_csv.hpp" -#include "fud_print.hpp" - namespace fud { } // namespace fud @@ -50,11 +48,9 @@ FudStatus Csv::parseFromFilenameUnbuffered( Option dirFdOption, size_t maxExtraAttempts) { - debugPrint(u8"Enter parse from filename\n"); auto fileResult{RegularFile::open(filename, FileAccessMode::Read, flags, std::move(dirFdOption))}; if (fileResult.isError()) { - debugPrint(u8"Error opening file: {}\n", FudStatusToString(fileResult.getError())); return fileResult.takeError(); } @@ -70,11 +66,9 @@ FudStatus Csv::parseFromFilenameBuffered( Option dirFdOption, size_t maxExtraAttempts) { - debugPrint(u8"Enter parse from filename\n"); auto fileResult{RegularFile::open(filename, FileAccessMode::Read, flags, std::move(dirFdOption))}; if (fileResult.isError()) { - debugPrint(u8"Error opening file: {}\n", FudStatusToString(fileResult.getError())); return fileResult.takeError(); } @@ -104,8 +98,6 @@ FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t return readResult.status; } - debugPrint(u8"Working with {} columns\n", csv.numColumns); - csv.numLines = 1; while (readResult.status == FudStatus::Success) { auto lineResult = scanLine(csv, file, maxExtraAttempts, rawSize); @@ -113,7 +105,6 @@ FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t readResult.bytesDrained += lineResult.bytesDrained; if (readResult.status == FudStatus::Success || readResult.status == FudStatus::Partial) { csv.numLines++; - debugPrint(u8"Read additional line - total of {}\n", csv.numLines); } } @@ -126,12 +117,9 @@ FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t } if (std::numeric_limits::max() / csv.numLines < csv.numColumns) { - debugPrint(u8"Fail: csv.numlines = {}, csv.numColumns = {}\n", csv.numLines, csv.numColumns); return FudStatus::Failure; } - debugPrint(u8"Working with {} lines\n", csv.numLines); - auto reserveStatus = csv.entries.reserve(csv.numLines * csv.numColumns); if (reserveStatus != FudStatus::Success) { return reserveStatus; @@ -142,8 +130,6 @@ FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t return reserveStatus; } - debugPrint(u8"Reserved space - {}\n", rawSize + 1); - auto fillStatus = fillBuffer(csv, file, maxExtraAttempts, rawSize); if (fillStatus != FudStatus::Success) { @@ -166,8 +152,6 @@ FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, size_t maxE template DrainResult readHeader(Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize) { - debugPrint(u8"Entered read header\n"); - DrainResult readResult{}; auto lineEnding{newlineText(csv.newlineDelimiter)}; @@ -183,12 +167,10 @@ DrainResult readHeader(Csv& csv, File& file, size_t maxExtraAttempts, size_t& ra readResult.status = drainResult.status; readResult.bytesDrained += drainResult.bytesDrained; if (readResult.status != FudStatus::Success) { - debugPrint(u8"Failed to read: {}", FudStatusToString(readResult.status)); return readResult; } if (csv.strictUtf8 && not utf8Char.valid()) { - debugPrint(u8"UTF8 invalid\n"); readResult.status = FudStatus::Utf8Invalid; return readResult; } @@ -231,7 +213,6 @@ DrainResult readHeader(Csv& csv, File& file, size_t maxExtraAttempts, size_t& ra template DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize) { - debugPrint(u8"Entered scanLine\n"); DrainResult readResult{}; auto lineEnding{newlineText(csv.newlineDelimiter)}; @@ -257,8 +238,6 @@ DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t break; } - debugPrint(u8"{}", utf8Char.data()); - if (maybeNewline and utf8Char != Utf8{Ascii{lineEnding[1]}}) { rawSize += 2; maybeNewline = false; @@ -300,12 +279,7 @@ DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t } } - if (numColumns > 0) { - debugPrint(u8"\n - Read line above with {} columns \n", numColumns); - } - if (numColumns == 0) { - debugPrint(u8"Read no additional columns\n"); readResult.status = FudStatus::Empty; return readResult; } @@ -343,7 +317,6 @@ FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSi currentEntry.m_data = csv.buffer.data() + sizeCounter; size_t numEntries = csv.numLines * csv.numColumns; - debugPrint(u8"Working over {} entries\n", numEntries); for (size_t entryIndex = 0; entryIndex < numEntries;) { addToSize = false; Utf8 utf8Char{}; @@ -421,7 +394,6 @@ FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSi break; case 0: default: - debugPrint(u8"Char size is ??? {}\n", charSize); charSize = 0; break; } @@ -433,21 +405,13 @@ FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSi } } - debugPrint( - u8"Buffer, with current size = {} and sizeCounter, = {}:\n-----\n{}\n-----\n", - csv.buffer.size(), - sizeCounter, - StringView{csv.buffer.size(), csv.buffer.data()}); - const auto* data = csv.buffer.data(); for (auto& entry : csv.entries) { entry.m_data = data; data += entry.m_length; - debugPrint(u8"Entry = {}\n", entry); } if (rawSize != sizeCounter) { - debugPrint(u8"Invalid: rawSize == {}, sizeCounter == {}"); return FudStatus::Failure; } @@ -455,4 +419,18 @@ FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSi } // NOLINTEND(readability-function-cognitive-complexity) +[[nodiscard]] Result, FudStatus> Csv::entry(size_t line, size_t column) const +{ + if (line > numLines || column > numColumns) { + return Error{FudStatus::IndexInvalid}; + } + + StringView entry = entries[(line * numColumns) + column]; + if (entry.length() == 0) { + return Okay{Option{NullOpt}}; + } + + return Okay{Option{entry}}; +} + } // namespace fud -- cgit v1.2.3