6#include "string_view_stream.hpp"
12#include <unordered_map>
38 std::unique_ptr<std::istream> ss(
new std::stringstream(std::string(in)));
53 return CSVReader(std::move(stream), format);
60 return parse(in, format);
71 inline CSVReader operator ""_csv(
const char* in,
size_t n) {
80 inline CSVReader operator ""_csv_no_header(
const char* in,
size_t n) {
89 std::unordered_map<std::string, DataType>
csv_data_types(
const std::string&);
97 for (
auto it = reader.
begin(); it != reader.
end(); ++it);
112 auto head = internals::get_csv_head(filename);
121 std::distance(col_names.begin(), std::find(col_names.begin(), col_names.end(), col_name));
Main class for parsing CSVs from files and in-memory sources.
CSVFormat get_format() const
Return the format of the original raw CSV.
CSV_CONST iterator end() const noexcept
A placeholder for the imaginary past-the-end row in a CSV.
CONSTEXPR size_t n_rows() const noexcept
Retrieves the number of rows that have been read so far.
std::vector< std::string > get_col_names() const
Return the CSV's column names as a vector of strings.
iterator begin()
Return an iterator to the first row in the reader.
Lightweight istream over csv::string_view with zero copy.
A standalone header file containing shared code.
Defines functionality needed for basic CSV parsing.
Implements data type parsing functionality.
The all encompassing namespace.
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.
CSVReader parse_unsafe(csv::string_view in, CSVFormat format=CSVFormat::guess_csv())
Parse CSV from an in-memory view with zero copy.
CSVFileInfo get_file_info(const std::string &filename)
Get basic information about a CSV file.
CSVReader parse(csv::string_view in, const CSVFormat &format=CSVFormat::guess_csv())
Parse CSV from a string view, copying the input into an owned buffer.
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.
CSVReader parse_no_header(csv::string_view in)
Parses a CSV string with no headers.
constexpr int CSV_NOT_FOUND
Integer indicating a requested column wasn't found.
std::unordered_map< std::string, DataType > csv_data_types(const std::string &filename)
Useful for uploading CSV files to SQL databases.
nonstd::string_view string_view
The string_view class used by this library.
Returned by get_file_info()
size_t n_cols
Number of columns in a CSV.
std::vector< std::string > col_names
CSV column names.
char delim
Delimiting character.
std::string filename
Filename.
size_t n_rows
Number of rows in a file.