summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/fud_csv.cpp48
1 files changed, 31 insertions, 17 deletions
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<TextBuffer&&> bufferOption,
StringView filename,
OpenFlags flags,
Option<int> dirFdOption,
- Option<size_t> 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<int> 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 <typename File>
-DrainResult readHeader(Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t& rawSize);
+DrainResult readHeader(Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize);
template <typename File>
-DrainResult scanLine(const Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t& rawSize);
+DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize);
template <typename File>
-FudStatus fillBuffer(Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t rawSize);
+FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSize);
-FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, Option<size_t> 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<size_t> maxExtraAttempts)
+FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, size_t maxExtraAttempts)
{
static_cast<void>(csv);
constexpr size_t BufferSize = 256;
@@ -150,7 +164,7 @@ FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, Option<size
// NOLINTBEGIN(readability-function-cognitive-complexity)
template <typename File>
-DrainResult readHeader(Csv& csv, File& file, Option<size_t> 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<size_t> maxExtraAttempts, si
}
template <typename File>
-DrainResult scanLine(const Csv& csv, File& file, Option<size_t> 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<size_t> maxExtraAttempts
}
template <typename File>
-FudStatus fillBuffer(Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t rawSize)
+FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSize)
{
static_cast<void>(rawSize);