From 8f12614f2da8221438a3807b1d234517650fbdb6 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 2 Jan 2025 16:27:56 -0600 Subject: Clang tidy fixes. --- source/fud_csv.cpp | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'source') diff --git a/source/fud_csv.cpp b/source/fud_csv.cpp index 198aeca..e1ecf72 100644 --- a/source/fud_csv.cpp +++ b/source/fud_csv.cpp @@ -43,41 +43,55 @@ Csv Csv::make(Allocator& entryAllocator, Allocator& bufferAllocator) return csv; } -FudStatus Csv::parseFromFilename( +FudStatus Csv::parseFromFilenameUnbuffered( Csv& csv, - Option bufferOption, StringView filename, OpenFlags flags, Option dirFdOption, - Option maxExtraAttempts) + size_t maxExtraAttempts) { debugPrint(u8"Enter parse from filename\n"); - auto fileResult{RegularFile::open(filename, FileAccessMode::Read, flags, dirFdOption)}; + 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(); } - if (bufferOption.hasValue()) { - auto bufferedFile{BufferedRegularFile::make(fileResult.takeOkay(), std::move(bufferOption.value()))}; - return parseFromBufferedFile(csv, bufferedFile, maxExtraAttempts); - } - auto unbufferedFile{fileResult.takeOkay()}; return parseFromUnbufferedFile(csv, std::move(unbufferedFile), maxExtraAttempts); } +FudStatus Csv::parseFromFilenameBuffered( + Csv& csv, + TextBuffer&& bufferOption, + StringView filename, + OpenFlags flags, + 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(); + } + + auto bufferedFile{BufferedRegularFile::make(fileResult.takeOkay(), std::move(bufferOption))}; + return parseFromBufferedFile(csv, bufferedFile, maxExtraAttempts); +} + template -DrainResult readHeader(Csv& csv, File& file, Option maxExtraAttempts, size_t& rawSize); +DrainResult readHeader(Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize); template -DrainResult scanLine(const Csv& csv, File& file, Option maxExtraAttempts, size_t& rawSize); +DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize); template -FudStatus fillBuffer(Csv& csv, File& file, Option maxExtraAttempts, size_t rawSize); +FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSize); -FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, Option maxExtraAttempts) +FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t maxExtraAttempts) { size_t rawSize = 0; DrainResult readResult{readHeader(csv, file, maxExtraAttempts, rawSize)}; @@ -139,7 +153,7 @@ FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, Option return FudStatus::Success; } -FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, Option maxExtraAttempts) +FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, size_t maxExtraAttempts) { static_cast(csv); constexpr size_t BufferSize = 256; @@ -150,7 +164,7 @@ FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, Option -DrainResult readHeader(Csv& csv, File& file, Option maxExtraAttempts, size_t& rawSize) +DrainResult readHeader(Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize) { debugPrint(u8"Entered read header\n"); @@ -215,7 +229,7 @@ DrainResult readHeader(Csv& csv, File& file, Option maxExtraAttempts, si } template -DrainResult scanLine(const Csv& csv, File& file, Option maxExtraAttempts, size_t& rawSize) +DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize) { debugPrint(u8"Entered scanLine\n"); DrainResult readResult{}; @@ -305,7 +319,7 @@ DrainResult scanLine(const Csv& csv, File& file, Option maxExtraAttempts } template -FudStatus fillBuffer(Csv& csv, File& file, Option maxExtraAttempts, size_t rawSize) +FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSize) { static_cast(rawSize); -- cgit v1.2.3