Vince's CSV Parser
Loading...
Searching...
No Matches
csv Namespace Reference

The all encompassing namespace. More...

Classes

struct  CSVError
 A diagnostic whose text remains valid for the lifetime of the error. More...
 
class  CSVField
 Data type representing individual CSV values. More...
 
struct  CSVFileInfo
 Returned by the file inspection utilities. More...
 
class  CSVFormat
 Stores information about how to parse a CSV file. More...
 
struct  CSVGuessResult
 Stores the inferred format of a CSV file. More...
 
class  CSVReader
 Main class for parsing CSVs from files and in-memory sources. More...
 
class  CSVRow
 Data structure for representing CSV rows. More...
 
class  DelimWriter
 Class for writing delimiter separated values files. More...
 
struct  is_invocable_returning
 
struct  is_invocable_returning_impl
 
struct  is_invocable_returning_impl< F, ReturnType, void_t< invoke_result_t< F, Args... > >, Args... >
 

Typedefs

using string_view = std::string_view
 The string_view class used by this library.
 
template<bool B, class T = void>
using enable_if_t = typename std::enable_if< B, T >::type
 
template<typename F , typename... Args>
using invoke_result_t = typename std::invoke_result< F, Args... >::type
 
template<typename... Ts>
using void_t = void
 

Enumerations

enum class  CSVConversionError {
  None = 0 , NotANumber , Overflow , FloatToInt ,
  NegativeToUnsigned
}
 Non-throwing CSVField conversion result. More...
 
enum class  CSVErrorCode {
  None , InvalidArgument , InvalidFormat , InvalidChunkSize ,
  OpenFailed , MappingFailed , ReadFailed , WriteFailed ,
  UnsupportedEncoding , RowTooLarge , RowLengthMismatch , ColumnNotFound ,
  IndexOutOfBounds , ConversionFailed , MissingKeyColumn , KeyNotFound ,
  DuplicateKey , UnkeyedFrame , ReadOnlyProxy , InvalidProxy ,
  KeyColumnProtected , UnsupportedOperation , SizeLimitExceeded
}
 Operational failures reported through CSVError. More...
 
enum class  VariableColumnPolicy { THROW = -1 , IGNORE_ROW = 0 , KEEP = 1 , KEEP_NON_EMPTY = 2 }
 Determines how to handle rows that are shorter or longer than the majority. More...
 
enum class  ColumnNamePolicy { EXACT = 0 , CASE_INSENSITIVE = 1 }
 Determines how column name lookups are performed. More...
 
enum class  DataType {
  UNKNOWN = classify_scalar::scalar_invalid , CSV_NULL = classify_scalar::scalar_null , CSV_STRING = classify_scalar::scalar_string , CSV_BOOL = classify_scalar::scalar_bool ,
  CSV_INT8 = classify_scalar::scalar_int8 , CSV_INT16 = classify_scalar::scalar_int16 , CSV_INT32 = classify_scalar::scalar_int32 , CSV_INT64 = classify_scalar::scalar_int64 ,
  CSV_BIGINT = classify_scalar::scalar_bigint , CSV_DOUBLE = classify_scalar::scalar_float , CSV_TIMESTAMP = classify_scalar::scalar_timestamp , scalar_custom_begin = classify_scalar::scalar_custom_begin - 1
}
 Enumerates the different CSV field types recognized by this library. More...
 

Functions

const char * csv_conversion_error_message (CSVConversionError error) noexcept
 Return a stable human-readable description for a CSVConversionError.
 
 CSVRow::operator std::vector< std::string > () const
 
CSVRow::iterator operator+ (CSVRow::iterator::difference_type n, const CSVRow::iterator &it) noexcept
 
CSVRow::reverse_iterator operator+ (CSVRow::reverse_iterator::difference_type n, const CSVRow::reverse_iterator &it) noexcept
 
template<>
std::string CSVField::get< std::string > () const
 Retrieve this field's original string.
 
template<>
CONSTEXPR_14 csv::string_view CSVField::get< csv::string_view > () const
 Retrieve a view over this field's string.
 
template<>
CONSTEXPR_14 bool CSVField::try_get< csv::string_view > (csv::string_view &out) const noexcept
 
Utility Functions
std::unordered_map< std::string, DataType > csv_data_types (CSVReader &reader)
 
std::unordered_map< std::string, DataType > try_csv_data_types (CSVReader &reader, CSVError &error)
 Infer SQL-friendly column data types from an existing CSVReader.
 
template<typename Source >
auto try_csv_data_types (Source &&source, CSVError &error, const CSVFormat &format=CSVFormat::guess_csv()) -> decltype(CSVReader::try_open(std::forward< Source >(source), error, format), std::unordered_map< std::string, DataType >())
 Infer types from a filename, borrowed stream, or owned stream, reporting I/O errors.
 
template<typename... ReaderArgs, csv::enable_if_t< std::is_constructible< CSVReader, ReaderArgs... >::value, int > = 0>
std::unordered_map< std::string, DataType > csv_data_types (ReaderArgs &&... reader_args)
 Infer SQL-friendly column data types from any CSVReader constructor input.
 
template<typename State , typename Fn >
bool try_chunk_parallel_apply (CSVReader &reader, DataFrameExecutor &executor, std::vector< State > &states, Fn &&fn, CSVError &error, size_t chunk_size=50000)
 Apply a per-column batch function over a CSVReader using a reusable executor.
 
template<typename State , typename Fn >
void chunk_parallel_apply (CSVReader &reader, DataFrameExecutor &executor, std::vector< State > &states, Fn &&fn, size_t chunk_size=50000)
 
template<typename State , typename Fn >
bool try_chunk_parallel_apply (CSVReader &reader, std::vector< State > &states, Fn &&fn, CSVError &error, size_t chunk_size=50000)
 Apply a per-column batch function over a CSVReader with a temporary executor.
 
template<typename State , typename Fn >
void chunk_parallel_apply (CSVReader &reader, std::vector< State > &states, Fn &&fn, size_t chunk_size=50000)
 
CSVFileInfo try_get_file_info (const std::string &filename, CSVError &error)
 Get basic information about a CSV file.
 
CSVFileInfo get_file_info (const std::string &filename)
 
std::vector< std::string > try_get_col_names (csv::string_view filename, CSVError &error, const CSVFormat &format=CSVFormat::guess_csv())
 Get the column names of a CSV file using just the first 500KB.
 
long long try_get_col_pos (csv::string_view filename, csv::string_view col_name, CSVError &error, const CSVFormat &format=CSVFormat::guess_csv())
 Find a column position, returning CSV_NOT_FOUND for an absent name or on failure.
 
std::vector< std::string > get_col_names (csv::string_view filename, const CSVFormat &format=CSVFormat::guess_csv())
 Get the column names of a CSV file using just the first 500KB.
 
long long get_col_pos (csv::string_view filename, csv::string_view col_name, const CSVFormat &format=CSVFormat::guess_csv())
 Find the position of a column in a CSV file or CSV_NOT_FOUND otherwise.
 
Shorthand Parsing Functions

Convenience functions for parsing small strings

std::unique_ptr< CSVReader > try_parse (csv::string_view in, CSVError &error, const CSVFormat &format=CSVFormat::guess_csv())
 Parse CSV from a string view, copying the input into an owned buffer.
 
CSVReader parse (csv::string_view in, const CSVFormat &format=CSVFormat::guess_csv())
 
std::unique_ptr< CSVReader > try_parse_unsafe (csv::string_view in, CSVError &error, const CSVFormat &format=CSVFormat::guess_csv())
 Parse CSV from an in-memory view with zero copy.
 
CSVReader parse_unsafe (csv::string_view in, const CSVFormat &format=CSVFormat::guess_csv())
 
CSVReader parse_no_header (csv::string_view in)
 Parses a CSV string with no headers.
 
CSVReader operator""_csv (const char *in, size_t n)
 Parse a RFC 4180 CSV string.
 
CSVReader operator""_csv_no_header (const char *in, size_t n)
 A shorthand for csv::parse_no_header().
 

Variables

constexpr int CSV_NOT_FOUND = -1
 Integer indicating a requested column wasn't found.
 
constexpr unsigned CHAR_OFFSET = std::numeric_limits<char>::is_signed ? 128 : 0
 Offset to convert char into array index.
 

CSV Writing

template<class OutputStream >
using CSVWriter = DelimWriter< OutputStream, ',', '"'>
 An alias for csv::DelimWriter for writing standard CSV files.
 
template<class OutputStream >
using TSVWriter = DelimWriter< OutputStream, '\t', '"'>
 Class for writing tab-separated values files.
 
template<class OutputStream >
CSVWriter< OutputStream > make_csv_writer (OutputStream &out, bool quote_minimal=true)
 Return a csv::CSVWriter over the output stream.
 
template<class OutputStream >
TSVWriter< OutputStream > make_tsv_writer (OutputStream &out, bool quote_minimal=true)
 Return a csv::TSVWriter over the output stream.
 

Detailed Description

The all encompassing namespace.

Typedef Documentation

◆ CSVWriter

template<class OutputStream >
using csv::CSVWriter = typedef DelimWriter<OutputStream, ',', '"'>

An alias for csv::DelimWriter for writing standard CSV files.

See also
csv::DelimWriter::operator<<()
Note
Use csv::make_csv_writer() to instantiate this class over an actual output stream.

Definition at line 969 of file csv_writer.hpp.

◆ enable_if_t

template<bool B, class T = void>
using csv::enable_if_t = typedef typename std::enable_if<B, T>::type

Definition at line 210 of file common.hpp.

◆ invoke_result_t

template<typename F , typename... Args>
using csv::invoke_result_t = typedef typename std::invoke_result<F, Args...>::type

Definition at line 223 of file common.hpp.

◆ string_view

The string_view class used by this library.

Definition at line 182 of file common.hpp.

◆ TSVWriter

template<class OutputStream >
using csv::TSVWriter = typedef DelimWriter<OutputStream, '\t', '"'>

Class for writing tab-separated values files.

See also
csv::DelimWriter::write_row()
csv::DelimWriter::operator<<()
Note
Use csv::make_tsv_writer() to instantiate this class over an actual output stream.

Definition at line 980 of file csv_writer.hpp.

◆ void_t

template<typename... Ts>
using csv::void_t = typedef void

Definition at line 230 of file common.hpp.

Enumeration Type Documentation

◆ ColumnNamePolicy

enum class csv::ColumnNamePolicy
strong

Determines how column name lookups are performed.

Enumerator
EXACT 

Case-sensitive match (default)

CASE_INSENSITIVE 

Case-insensitive match.

Definition at line 37 of file csv_format.hpp.

◆ CSVConversionError

enum class csv::CSVConversionError
strong

Non-throwing CSVField conversion result.

Returned by CSVField::as() inside std::expected, and used internally by CSVField::get() and CSVField::try_get() to keep throwing and non-throwing conversions on the same rules.

See also
csv_conversion_error_message()
Enumerator
None 

Conversion succeeded.

NotANumber 

The field is not compatible with the requested target type.

Overflow 

The parsed value does not fit in the requested target type.

FloatToInt 

A floating point field was requested as an integral type.

NegativeToUnsigned 

A negative value was requested as an unsigned type.

Definition at line 23 of file csv_error.hpp.

◆ CSVErrorCode

enum class csv::CSVErrorCode
strong

Operational failures reported through CSVError.

Enumerator
None 

Success, including end-of-stream without a row.

InvalidArgument 

Invalid operation input, such as a null stream or zero batch size.

InvalidFormat 

Conflicting parsing characters or an unresolved delimiter query.

InvalidChunkSize 

Configured read-window size is outside the supported byte limits.

OpenFailed 

A native file could not be opened, including initial input mapping.

MappingFailed 

A subsequent input-file region could not be memory-mapped; see CSVError::system.

ReadFailed 

The input stream reported an I/O failure rather than ordinary EOF.

WriteFailed 

Writing, flushing, or closing the output failed.

UnsupportedEncoding 

A UTF-16/UTF-32 BOM was found; transcode the input to UTF-8 first.

RowTooLarge 

A complete record could not fit within the configured read window.

RowLengthMismatch 

A record's field count violates the configured variable-column policy.

ColumnNotFound 

A requested name is absent from the visible column schema.

IndexOutOfBounds 

A row/column position exceeds the visible schema or physical record width.

ConversionFailed 

A DataFrame field/key conversion failed; context describes the cause.

MissingKeyColumn 

Keyed construction has an empty key-column name or a name absent from the schema.

KeyNotFound 

A requested row key is absent from the frame's key index.

DuplicateKey 

A key conflicts with an existing row under the requested insertion/duplicate policy.

UnkeyedFrame 

A key-based operation was requested on a positional-only frame.

ReadOnlyProxy 

Mutation was requested through a cell, row, or column without edit permission.

InvalidProxy 

A proxy is unbound or a column proxy was invalidated by structural mutation.

KeyColumnProtected 

Removing the column that supplies the frame's stored keys is prohibited.

UnsupportedOperation 

The operation cannot be performed for this frame, such as inserting into a custom-key frame.

SizeLimitExceeded 

Combined preserved string-view key bytes exceed std::string::max_size().

Definition at line 61 of file csv_error.hpp.

◆ DataType

enum class csv::DataType
strong

Enumerates the different CSV field types recognized by this library.

Enumerator
CSV_NULL 

Empty string.

CSV_STRING 

Non-scalar string.

CSV_BOOL 

Boolean value.

CSV_INT8 

8-bit integer

CSV_INT16 

16-bit integer

CSV_INT32 

32-bit integer

CSV_INT64 

64-bit integer

CSV_BIGINT 

Integer too large to fit in 64 bits.

CSV_DOUBLE 

Floating point value.

CSV_TIMESTAMP 

Timestamp value.

Definition at line 14 of file data_type.hpp.

◆ VariableColumnPolicy

enum class csv::VariableColumnPolicy
strong

Determines how to handle rows that are shorter or longer than the majority.

Definition at line 29 of file csv_format.hpp.

Function Documentation

◆ chunk_parallel_apply() [1/2]

template<typename State , typename Fn >
void csv::chunk_parallel_apply ( CSVReader &  reader,
DataFrameExecutor &  executor,
std::vector< State > &  states,
Fn &&  fn,
size_t  chunk_size = 50000 
)
inline

Definition at line 211 of file csv_utility.hpp.

◆ chunk_parallel_apply() [2/2]

template<typename State , typename Fn >
void csv::chunk_parallel_apply ( CSVReader &  reader,
std::vector< State > &  states,
Fn &&  fn,
size_t  chunk_size = 50000 
)
inline

Definition at line 243 of file csv_utility.hpp.

◆ csv_conversion_error_message()

const char * csv::csv_conversion_error_message ( CSVConversionError  error)
inlinenoexcept

Return a stable human-readable description for a CSVConversionError.

Definition at line 53 of file csv_error.hpp.

◆ csv_data_types() [1/2]

std::unordered_map< std::string, DataType > csv::csv_data_types ( CSVReader &  reader)

Definition at line 6 of file csv_utility.cpp.

◆ csv_data_types() [2/2]

template<typename... ReaderArgs, csv::enable_if_t< std::is_constructible< CSVReader, ReaderArgs... >::value, int > = 0>
std::unordered_map< std::string, DataType > csv::csv_data_types ( ReaderArgs &&...  reader_args)
inline

Infer SQL-friendly column data types from any CSVReader constructor input.

This convenience overload forwards its arguments directly to CSVReader, so it supports filenames, std::istream sources, owned streams, and custom CSVFormat combinations without additional wrapper code.

Example
std::istringstream input("name,age\nAlice,30\nBob,41\n");
CSVFormat format;
format.delimiter(',').header_row(0);
auto dtypes = csv::csv_data_types(input, format);
Stores information about how to parse a CSV file.
CSVFormat & delimiter(char delim)
Sets the delimiter of the CSV file.
CSVFormat & header_row(int row)
Sets the header row.

Definition at line 158 of file csv_utility.hpp.

◆ CSVField::get< csv::string_view >()

template<>
CONSTEXPR_14 csv::string_view csv::CSVField::get< csv::string_view > ( ) const

Retrieve a view over this field's string.

Warning
The source text must outlive the returned view. A retained row or field iterator keeps its parsing buffer alive.

Definition at line 886 of file csv_row.hpp.

◆ CSVField::get< std::string >()

template<>
std::string csv::CSVField::get< std::string > ( ) const
inline

Retrieve this field's original string.

Definition at line 876 of file csv_row.hpp.

◆ CSVField::try_get< csv::string_view >()

template<>
CONSTEXPR_14 bool csv::CSVField::try_get< csv::string_view > ( csv::string_view &  out) const
noexcept

Definition at line 903 of file csv_row.hpp.

◆ CSVRow::operator std::vector< std::string >()

csv::CSVRow::operator std::vector< std::string > ( ) const

Definition at line 67 of file csv_row.cpp.

◆ get_col_names()

std::vector< std::string > csv::get_col_names ( csv::string_view  filename,
const CSVFormat &  format = CSVFormat::guess_csv() 
)
inline

Get the column names of a CSV file using just the first 500KB.

Definition at line 316 of file csv_utility.hpp.

◆ get_col_pos()

long long csv::get_col_pos ( csv::string_view  filename,
csv::string_view  col_name,
const CSVFormat &  format = CSVFormat::guess_csv() 
)
inline

Find the position of a column in a CSV file or CSV_NOT_FOUND otherwise.

Definition at line 327 of file csv_utility.hpp.

◆ get_file_info()

CSVFileInfo csv::get_file_info ( const std::string &  filename)
inline

Definition at line 281 of file csv_utility.hpp.

◆ make_csv_writer()

template<class OutputStream >
CSVWriter< OutputStream > csv::make_csv_writer ( OutputStream &  out,
bool  quote_minimal = true 
)
inline

Return a csv::CSVWriter over the output stream.

Definition at line 984 of file csv_writer.hpp.

◆ make_tsv_writer()

template<class OutputStream >
TSVWriter< OutputStream > csv::make_tsv_writer ( OutputStream &  out,
bool  quote_minimal = true 
)
inline

Return a csv::TSVWriter over the output stream.

Definition at line 990 of file csv_writer.hpp.

◆ operator""_csv()

CSVReader csv::operator""_csv ( const char *  in,
size_t  n 
)
inline

Parse a RFC 4180 CSV string.

String literals have static storage duration, so the zero-copy path is safe here.

Example
TEST_CASE( "Test Escaped Comma", "[read_csv_comma]" ) {
auto rows = "A,B,C\r\n" // Header row
"123,\"234,345\",456\r\n"
"1,2,3\r\n"
"1,2,3"_csv;
CSVRow row;
rows.read_row(row);
REQUIRE( vector<string>(row) ==
vector<string>({"123", "234,345", "456"}));
}
Data structure for representing CSV rows.
Definition csv_row.hpp:533

Definition at line 99 of file csv_utility.hpp.

◆ operator""_csv_no_header()

CSVReader csv::operator""_csv_no_header ( const char *  in,
size_t  n 
)
inline

A shorthand for csv::parse_no_header().

String literals have static storage duration, so the zero-copy path is safe here.

Definition at line 108 of file csv_utility.hpp.

◆ operator+() [1/2]

CSVRow::iterator csv::operator+ ( CSVRow::iterator::difference_type  n,
const CSVRow::iterator &  it 
)
noexcept

Definition at line 311 of file csv_row.cpp.

◆ operator+() [2/2]

CSVRow::reverse_iterator csv::operator+ ( CSVRow::reverse_iterator::difference_type  n,
const CSVRow::reverse_iterator &  it 
)
noexcept

Definition at line 399 of file csv_row.cpp.

◆ parse()

CSVReader csv::parse ( csv::string_view  in,
const CSVFormat &  format = CSVFormat::guess_csv() 
)
inline

Definition at line 50 of file csv_utility.hpp.

◆ parse_no_header()

CSVReader csv::parse_no_header ( csv::string_view  in)
inline

Parses a CSV string with no headers.

Definition at line 85 of file csv_utility.hpp.

◆ parse_unsafe()

CSVReader csv::parse_unsafe ( csv::string_view  in,
const CSVFormat &  format = CSVFormat::guess_csv() 
)
inline

Definition at line 75 of file csv_utility.hpp.

◆ try_chunk_parallel_apply() [1/2]

template<typename State , typename Fn >
bool csv::try_chunk_parallel_apply ( CSVReader &  reader,
DataFrameExecutor &  executor,
std::vector< State > &  states,
Fn &&  fn,
CSVError &  error,
size_t  chunk_size = 50000 
)
inline

Apply a per-column batch function over a CSVReader using a reusable executor.

Reads the source in chunks, promotes each chunk into a temporary DataFrame, and applies fn(column, states[column.index()]).

Callbacks may treat each batch DataFrame as read-mostly, and sparse overlay cell edits are synchronized at row granularity. If you need more involved batch orchestration, use CSVReader::read_chunk() and construct a batch-scoped DataFrame yourself.

Exceptions
std::invalid_argumentif chunk_size == 0

Definition at line 195 of file csv_utility.hpp.

◆ try_chunk_parallel_apply() [2/2]

template<typename State , typename Fn >
bool csv::try_chunk_parallel_apply ( CSVReader &  reader,
std::vector< State > &  states,
Fn &&  fn,
CSVError &  error,
size_t  chunk_size = 50000 
)
inline

Apply a per-column batch function over a CSVReader with a temporary executor.

This is the convenience overload for the common case where callers do not need to reuse worker threads across multiple reader pipelines.

Definition at line 230 of file csv_utility.hpp.

◆ try_csv_data_types() [1/2]

std::unordered_map< std::string, DataType > csv::try_csv_data_types ( CSVReader &  reader,
CSVError &  error 
)

Infer SQL-friendly column data types from an existing CSVReader.

This consumes rows from reader using the chunked ETL path and returns one inferred DataType per column name.

Definition at line 14 of file csv_utility.cpp.

◆ try_csv_data_types() [2/2]

template<typename Source >
auto csv::try_csv_data_types ( Source &&  source,
CSVError &  error,
const CSVFormat &  format = CSVFormat::guess_csv() 
) -> decltype(CSVReader::try_open(std::forward<Source>(source), error, format), std::unordered_map<std::string, DataType>())
inline

Infer types from a filename, borrowed stream, or owned stream, reporting I/O errors.

Definition at line 127 of file csv_utility.hpp.

◆ try_get_col_names()

std::vector< std::string > csv::try_get_col_names ( csv::string_view  filename,
CSVError &  error,
const CSVFormat &  format = CSVFormat::guess_csv() 
)
inline

Get the column names of a CSV file using just the first 500KB.

Definition at line 290 of file csv_utility.hpp.

◆ try_get_col_pos()

long long csv::try_get_col_pos ( csv::string_view  filename,
csv::string_view  col_name,
CSVError &  error,
const CSVFormat &  format = CSVFormat::guess_csv() 
)
inline

Find a column position, returning CSV_NOT_FOUND for an absent name or on failure.

An absent name is not an error; inspect error to distinguish an I/O failure.

Definition at line 303 of file csv_utility.hpp.

◆ try_get_file_info()

CSVFileInfo csv::try_get_file_info ( const std::string &  filename,
CSVError &  error 
)
inline

Get basic information about a CSV file.

#include "csv.hpp"
#include <iostream>
int main(int argc, char** argv) {
using namespace csv;
if (argc < 2) {
std::cout << "Usage: " << argv[0] << " [file]" << std::endl;
exit(1);
}
std::string file = argv[1];
auto info = get_file_info(file);
std::cout << file << std::endl << "Columns: ";
for (size_t i = 0; i < info.col_names.size(); i++) {
if (i) std::cout << ", ";
std::cout << info.col_names[i];
}
std::cout << std::endl
<< "Dimensions: " << info.n_rows << " rows x " << info.n_cols << " columns" << std::endl
<< "Delimiter: " << info.delim << std::endl;
return 0;
}
The all encompassing namespace.

Definition at line 258 of file csv_utility.hpp.

◆ try_parse()

std::unique_ptr< CSVReader > csv::try_parse ( csv::string_view  in,
CSVError &  error,
const CSVFormat &  format = CSVFormat::guess_csv() 
)
inline

Parse CSV from a string view, copying the input into an owned buffer.

Safe for any string_view regardless of the caller's ownership of the underlying memory.

Example
TEST_CASE( "Test Escaped Quote", "[read_csv_quote]" ) {
// Per RFC 1480, escaped quotes should be doubled up
auto csv_string = GENERATE(as<std::string> {},
(
"A,B,C\r\n" // Header row
"123,\"234\"\"345\",456\r\n"
"123,\"234\"345\",456\r\n" // Unescaped single quote (not strictly valid)
"123,\"234\"345\",\"456\"" // Quoted field at the end
"123, \"234\"345\",\"456\"" // Quoted field w/ leading whitespace
),
(
"\"A\",\"B\",\"C\"\r\n" // Header row
"123,\"234\"\"345\",456\r\n"
"123,\"234\"345\",456\r\n" // Unescaped single quote (not strictly valid)
"123,\"234\"345\",\"456\"" // Quoted field at the end
"123,\"234\"345\",\"456\"" // Quoted field w/ leading whitespace
)
);
SECTION("Escaped Quote") {
auto rows = parse(csv_string);
REQUIRE(rows.get_col_names() == vector<string>({ "A", "B", "C" }));
// Expected Results: Double " is an escape for a single "
vector<string> correct_row = { "123", "234\"345", "456" };
for (auto& row : rows) {
REQUIRE(vector<string>(row) == correct_row);
}
}
}

Definition at line 42 of file csv_utility.hpp.

◆ try_parse_unsafe()

std::unique_ptr< CSVReader > csv::try_parse_unsafe ( csv::string_view  in,
CSVError &  error,
const CSVFormat &  format = CSVFormat::guess_csv() 
)
inline

Parse CSV from an in-memory view with zero copy.

WARNING: Non-owning path. The caller must ensure in's backing memory remains valid and immutable while the reader may request additional rows from the source stream.

Rows already obtained from the reader remain valid, but unread rows still depend on the source view staying alive.

Definition at line 67 of file csv_utility.hpp.

Variable Documentation

◆ CHAR_OFFSET

constexpr unsigned csv::CHAR_OFFSET = std::numeric_limits<char>::is_signed ? 128 : 0
constexpr

Offset to convert char into array index.

Definition at line 497 of file common.hpp.

◆ CSV_NOT_FOUND

constexpr int csv::CSV_NOT_FOUND = -1
constexpr

Integer indicating a requested column wasn't found.

Definition at line 494 of file common.hpp.