19#ifndef MTCORE_CSV_WRITTER_HPP
20#define MTCORE_CSV_WRITTER_HPP
50 using Column = std::variant<i64, u64, Slice<const char>,
f64>;
61 template<WriterImpl WI>
63 static constexpr bool IsWriteThrough =
true;
71 if (
auto r = underlying.
write(opts.
quote); r.is_error()) {
79 while (splits.next().copy_if_present(cur)) {
90 if (
auto r = underlying.
write_all(cur); r.is_error()) {
93 written += cur.
size();
97 else if (!s.
empty()) {
98 if (
auto r = underlying.
write_all(s); r.is_error()) {
104 if (
auto r = underlying.
write(opts.
quote); r.is_error()) {
116 return print(underlying,
"{}{}", opts.
cr.
value(), opts.
lf);
118 return print(underlying,
"{}", opts.
lf);
126 while (
iter.next().copy_if_present(cur)) {
128 if (
auto r = (*
this)(
ColEnd{}); r.is_error()) {
132 written += r.value();
139 auto pr = std::visit(*
this, cur);
143 written += pr.value();
145 auto leRes = (*this)(
RowEnd{});
146 if (leRes.is_error()) {
147 return leRes.error();
149 written += leRes.value();
159 while (
iter.next().copy_if_present(cur)) {
160 if (
auto r = write(cur); r.is_error()) {
164 written += r.value();
181 template<WriterImpl WI>
SplitIter< T, Slice< T > > split(const Slice< T > &needle, const Slice< T > &haystack)
Splits a slice into smaller sub slices.
bool contains(const std::remove_const_t< T > &needle, const Slice< T > &haystack)
Checks whether a slice (the haystack) contains an element (the needle) Uses the equality operator of ...
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.
std::variant< i64, u64, Slice< const char >, f64 > Column
Column type.
std::variant< i64, u64, Slice< const char >, f64, Slice< const Column >, RowEnd, ColEnd > WriteElem
Elements that can be written to a CSV writer.
Success< void > success()
Creates a successful void Result object.
uint64_t u64
Alias for 64-bit unsigned ints.
int64_t i64
Alias for 64-bit ints.
double f64
Alias for 64-bit floats.
CSV namespace for CSV-related utilities.
Generic iterator defaults built on common contracts Does not guarantee performance of iterators Actua...
bool has_value() const noexcept
bool is_error() const noexcept
Checks if is an error Result.
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...
constexpr size_t size() const noexcept
Gets the size of a Slice.
constexpr bool empty() const noexcept
Checks if a Slice is empty.
decltype(auto) iter() const noexcept
Special output-only type for indicating the end of a colum.
CSV options for defining the CSV format.
Special output-only type for indicating the end of a row.
A writer that writes data to some sort of stream or buffer Note: the data elements written should be ...
Result< void, ErrType > write_n_times(const Slice< std::remove_const_t< WriteElem > > &s, size_t n)
Will write all the elements in a Slice N times If there is no room, will return the error OUT_OF_ROOM...
typename Impl::ErrType ErrType
Result< size_t, ErrType > write(const Slice< std::remove_const_t< WriteElem > > &s)
Will write as much of a Slice as possible.
Result< size_t, ErrType > write_all(const Slice< std::remove_const_t< WriteElem > > &s)
Will write all the elements in a Slice If there is no room, will return the error OUT_OF_ROOM Note: M...