1#ifndef MTCORE_CSV_COMMON_HPP
2#define MTCORE_CSV_COMMON_HPP
39 template<WriterImpl WI>
41 const char* codeStr =
"";
44 codeStr =
"INTERNAL_LIMIT_REACHED";
47 codeStr =
"UNEXPECTED_EOF";
50 codeStr =
"INVALID_LINE_ENDING";
53 codeStr =
"QUOTE_PREMATURELY_TERMINATED";
56 codeStr =
"UNEXPECTED_QUOTE";
59 codeStr =
"END_OF_FILE";
62 codeStr =
"ALLOCATION_FAILED";
65 codeStr =
"SIZE_EXCEEDED";
85 [[nodiscard]]
bool valid()
const;
93 template<WriterImpl WI>
97 const auto quote = options.quote;
98 if (field.
len < 2 || field[0] != quote) {
99 return writer.write_all(field);
129 if (
auto r =
writer.write(c); r.is_error()) {
136 if (nextChar == quote) {
148 if (
auto r =
writer.write(c); r.is_error()) {
constexpr auto nullopt
Placeholder value for an empty Optional.
io::Writer< csv::impl::Writer< WI > > writer(io::Writer< WI > &underlying, Options opts={})
Creates a CSV writer which will encode the data before writing it out.
#define ensure(check,...)
Ensures that a check holds true, aborts the program if not true Will print error if the condition is ...
#define mtdefer
Defer statement that will mtdefer execution until the scope is left, at which point the code will run...
Success< void > success()
Creates a successful void Result object.
uint64_t u64
Alias for 64-bit unsigned ints.
Slice< const char > unquote_quoted(Slice< const char > data, Options opts)
Result< size_t, typename io::Writer< WI >::ErrType > decode(io::Writer< WI > &writer, Slice< const char > field, const Options options={})
u64 quoted_regions(u64 m)
CSV namespace for CSV-related utilities.
static constexpr u64 chunkSize
@ QUOTE_PREMATURELY_TERMINATED
u64 bit_match_64(char ch, Slice< const char > s)
Represents a value that may or may not exist (an "Optional" value) Similar concept to std::optional,...
bool copy_if_present(std::remove_const_t< T > &out) const noexcept
Copies a value to a reference output destination if a value is present Designed to be used by simple ...
Represents a Result that may have an error (error code) or a success value A type of "void" means the...
A Slice which is just a pointer + length Accessing elements through the array operator will do bounds...
CSV options for defining the CSV format.
bool operator==(const ReadError &o) const
ReadErrorCode code
Error code.
static const ReadError SIZE_EXCEEDED
bool operator==(const ReadErrorCode &o) const
Result< size_t, typename io::Writer< WI >::ErrType > fmt(io::Writer< WI > &writer, const io::FormatOptions &)
bool operator!=(const ReadErrorCode &o) const
bool operator!=(const ReadError &o) const
static const ReadError ALLOCATION_FAILED
size_t pos
Human-readable position (i.e.
static const ReadError END_OF_FILE
A writer that writes data to some sort of stream or buffer Note: the data elements written should be ...