summaryrefslogtreecommitdiff
path: root/include/fud_csv.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/fud_csv.hpp')
-rw-r--r--include/fud_csv.hpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/include/fud_csv.hpp b/include/fud_csv.hpp
index efd37e6..38b1b81 100644
--- a/include/fud_csv.hpp
+++ b/include/fud_csv.hpp
@@ -22,6 +22,7 @@
#include "fud_status.hpp"
#include "fud_string_view.hpp"
#include "fud_text.hpp"
+#include "fud_utf8.hpp"
#include "fud_vector.hpp"
#include <functional> // reference_wrapper
@@ -29,52 +30,59 @@
namespace fud {
using TextBuffer = Vector<std::byte>;
-using CsvBuffer = Vector<std::byte>;
-using CsvLine = Vector<StringView>;
struct Csv {
/** \brief The number of lines of data in the CSV. */
- size_t numLines;
+ size_t numLines{0};
/** \brief The number of columns in the CSV. */
- size_t numColumns;
+ size_t numColumns{0};
/** \brief Buffer for each line with numColumns of StringView. */
- Vector<CsvLine> lines;
+ Vector<StringView> entries;
/** \brief Backing buffer for data. */
- CsvBuffer buffer;
+ Vector<utf8> buffer;
/** \separator for each column */
Utf8 columnDelimiter{Ascii{','}};
+ Utf8 quoteCharacter{Ascii{'"'}};
+
/** \separator for each line */
NewlineRepr newlineDelimiter{NewlineRepr::Posix};
- bool strict;
+ bool strictUtf8{true};
+
+ bool strictColumns{true};
+
+ bool strictQuote{false};
+
+ bool skipInitialSpace{false};
/** \brief Uses global Fud allocator for lines and backing buffer. */
static Csv makeDefault();
/** \brief Specify allocator to use for both lines and backing buffer. */
- static Csv makeSingleAllocator(Allocator& allocator);
+ static Csv makeWithSingleAllocator(Allocator& allocator);
/** \brief Specify allocator. */
- static Csv make(Allocator& lineAllocator, Allocator& bufferAllocator);
+ static Csv make(Allocator& entryAllocator, Allocator& bufferAllocator);
/** Consume and return the CSV. */
- static FudStatus parseCsvFromFilename(
+ static FudStatus parseFromFilename(
Csv& csv,
Option<TextBuffer&&> bufferOption,
StringView filename,
OpenFlags flags = OpenFlags{},
- Option<int> dirFdOption = NullOpt);
+ Option<int> dirFdOption = NullOpt,
+ Option<size_t> maxExtraAttempts = NullOpt);
// assumes file is at start
- static FudStatus parseCsvFromUnbufferedFile(Csv& csv, RegularFile&& file);
+ static FudStatus parseFromUnbufferedFile(Csv& csv, RegularFile&& file, Option<size_t> maxExtraAttempts);
// assumes file is at start
- static FudStatus parseCsvFromBufferedFile(Csv& csv, BufferedRegularFile& file);
+ static FudStatus parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, Option<size_t> maxExtraAttempts);
};
} // namespace fud