Vince's CSV Parser
csv_utility.hpp
1 #pragma once
2 #include "common.hpp"
3 #include "csv_format.hpp"
4 #include "csv_reader.hpp"
5 #include "data_type.hpp"
6 
7 #include <string>
8 #include <type_traits>
9 #include <unordered_map>
10 
11 namespace csv {
13  struct CSVFileInfo {
14  std::string filename;
15  std::vector<std::string> col_names;
16  char delim;
17  size_t n_rows;
18  size_t n_cols;
19  };
20 
25  CSVReader operator ""_csv(const char*, size_t);
26  CSVReader operator ""_csv_no_header(const char*, size_t);
30 
33  std::unordered_map<std::string, DataType> csv_data_types(const std::string&);
34  CSVFileInfo get_file_info(const std::string& filename);
35  int get_col_pos(csv::string_view filename, csv::string_view col_name,
36  const CSVFormat& format = CSVFormat::guess_csv());
38 }
Stores information about how to parse a CSV file.
Definition: csv_format.hpp:36
static CSVFormat guess_csv()
CSVFormat for guessing the delimiter.
Definition: csv_format.hpp:126
Main class for parsing CSVs from files and in-memory sources.
Definition: csv_reader.hpp:57
A standalone header file containing shared code.
Defines an object used to store CSV format settings.
Defines functionality needed for basic CSV parsing.
Implements data type parsing functionality.
The all encompassing namespace.
int get_col_pos(csv::string_view filename, csv::string_view col_name, const CSVFormat &format)
Find the position of a column in a CSV file or CSV_NOT_FOUND otherwise.
Definition: csv_utility.cpp:53
CSVFileInfo get_file_info(const std::string &filename)
Get basic information about a CSV file.
Definition: csv_utility.cpp:64
CSVReader parse(csv::string_view in, CSVFormat format)
Shorthand function for parsing an in-memory CSV string.
Definition: csv_utility.cpp:14
CSVReader parse_no_header(csv::string_view in)
Parses a CSV string with no headers.
Definition: csv_utility.cpp:23
std::unordered_map< std::string, DataType > csv_data_types(const std::string &filename)
Useful for uploading CSV files to SQL databases.
Definition: csv_stat.cpp:240
nonstd::string_view string_view
The string_view class used by this library.
Definition: common.hpp:75
Returned by get_file_info()
Definition: csv_utility.hpp:13
size_t n_cols
Number of columns in a CSV.
Definition: csv_utility.hpp:18
std::vector< std::string > col_names
CSV column names.
Definition: csv_utility.hpp:15
char delim
Delimiting character.
Definition: csv_utility.hpp:16
std::string filename
Filename.
Definition: csv_utility.hpp:14
size_t n_rows
Number of rows in a file.
Definition: csv_utility.hpp:17