|
Vince's CSV Parser
|
Data type representing individual CSV values. More...
#include <csv_row.hpp>
Public Member Functions | |
| constexpr | CSVField (csv::string_view _sv) noexcept |
| Constructs a CSVField from a string_view. | |
| CSVField (csv::string_view _sv, const internals::CSVFieldScalar &scalar) noexcept | |
| operator csv::string_view () const noexcept | |
| operator std::string () const | |
| template<typename T = std::string> | |
| T | get () const |
| Returns the value casted to the requested type, performing type checking before. | |
| template<typename T = std::string> | |
| std::expected< T, CSVConversionError > | as () const |
| Return this field as T, preserving conversion failure as CSVConversionError. | |
| template<typename T = std::string> | |
| bool | try_get (T &out) const noexcept |
| Non-throwing equivalent of get(). | |
| template<typename T > | |
| bool | try_get (T &out, CSVConversionError &error) const noexcept |
| Convert with the same rules as try_get(), retaining the failure reason. | |
| template<typename T > | |
| operator std::optional< T > () const | |
| Convert this field to std::optional<T>, returning std::nullopt when conversion fails. | |
| template<typename T = long long> | |
| bool | try_parse_hex (T &parsedValue) const |
| Parse a hexadecimal value, returning false if the value is not hex. | |
| bool | try_parse_decimal (long double &dVal, const char decimalSymbol='.') |
Attempts to parse a decimal (or integer) value using the given symbol, returning true if the value is numeric. | |
| bool | try_parse_timestamp (std::uint64_t &out) const noexcept |
| Parse this field as Unix milliseconds. | |
| template<typename T > | |
| bool | try_parse_timestamp (T &out) const noexcept |
| Parse this field as Unix milliseconds in a 64-bit unsigned integer. | |
| template<typename Rep , typename Period > | |
| bool | try_parse_timestamp (std::chrono::duration< Rep, Period > &out) const noexcept |
| Parse this field as a timestamp duration since the Unix epoch. | |
| template<typename Duration > | |
| bool | try_parse_timestamp (std::chrono::time_point< std::chrono::system_clock, Duration > &out) const noexcept |
| Parse this field as a std::chrono::system_clock time point. | |
| template<typename T > | |
| bool | operator== (T other) const noexcept |
| Compares the contents of this field to a numeric value. | |
| CONSTEXPR csv::string_view | get_sv () const noexcept |
| Return a string view over the field's contents. | |
| bool | is_null () const noexcept |
| Returns true if field is an empty string or string of whitespace characters. | |
| bool | is_str () const noexcept |
| Returns true if field is a non-numeric, non-empty string. | |
| bool | is_num () const noexcept |
| Returns true if field is an integer or float. | |
| bool | is_int () const noexcept |
| Returns true if field is an integer. | |
| bool | is_float () const noexcept |
| Returns true if field is a floating point value. | |
| bool | is_bool () const noexcept |
| Returns true if field is a boolean value. | |
| bool | is_timestamp () const noexcept |
| Returns true if field is a timestamp value. | |
| DataType | type () const noexcept |
| Return the type of the underlying CSV data. | |
| template<> | |
| long double | get () const |
| Retrieve this field's value as a long double. | |
| template<> | |
| CONSTEXPR bool | operator== (const char *other) const noexcept |
| Compares the contents of this field to a string. | |
| template<> | |
| CONSTEXPR bool | operator== (csv::string_view other) const noexcept |
| Compares the contents of this field to a string. | |
Data type representing individual CSV values.
CSVFields can be obtained by using CSVRow::operator[]
Ordinary queries and conversions are logically const: they may populate a private lazy cache, but preserve the field's text and interpretation. Custom decimal parsing explicitly changes interpretation and is non-const.
Definition at line 74 of file csv_row.hpp.
|
inlineexplicitconstexprnoexcept |
Constructs a CSVField from a string_view.
Definition at line 77 of file csv_row.hpp.
|
inlinenoexcept |
Definition at line 80 of file csv_row.hpp.
|
inline |
Return this field as T, preserving conversion failure as CSVConversionError.
Definition at line 162 of file csv_row.hpp.
|
inline |
Returns the value casted to the requested type, performing type checking before.
| std::runtime_error | Thrown if an invalid conversion is performed. |
Definition at line 140 of file csv_row.hpp.
|
inline |
Retrieve this field's value as a long double.
Definition at line 892 of file csv_row.hpp.
|
inlinenoexcept |
Return a string view over the field's contents.
Definition at line 317 of file csv_row.hpp.
|
inlinenoexcept |
Returns true if field is a boolean value.
Definition at line 339 of file csv_row.hpp.
|
inlinenoexcept |
Returns true if field is a floating point value.
Definition at line 336 of file csv_row.hpp.
|
inlinenoexcept |
Returns true if field is an integer.
Definition at line 331 of file csv_row.hpp.
|
inlinenoexcept |
Returns true if field is an empty string or string of whitespace characters.
Definition at line 320 of file csv_row.hpp.
|
inlinenoexcept |
Returns true if field is an integer or float.
Definition at line 326 of file csv_row.hpp.
|
inlinenoexcept |
Returns true if field is a non-numeric, non-empty string.
Definition at line 323 of file csv_row.hpp.
|
inlinenoexcept |
Returns true if field is a timestamp value.
Definition at line 342 of file csv_row.hpp.
|
inlinenoexcept |
Definition at line 105 of file csv_row.hpp.
|
inline |
Convert this field to std::optional<T>, returning std::nullopt when conversion fails.
This is a value-returning wrapper around try_get(), useful for C++17 callers that want non-throwing conversion without an output parameter.
Definition at line 212 of file csv_row.hpp.
|
inline |
Definition at line 109 of file csv_row.hpp.
|
noexcept |
Compares the contents of this field to a string.
Definition at line 913 of file csv_row.hpp.
|
noexcept |
Compares the contents of this field to a string.
Definition at line 920 of file csv_row.hpp.
|
inlinenoexcept |
Compares the contents of this field to a numeric value.
If this field does not contain a numeric value, then all comparisons return false.
0.000001 of each other.Definition at line 303 of file csv_row.hpp.
|
inlinenoexcept |
Non-throwing equivalent of get().
Applies the same type checks and conversions; returns true and writes to out on success, or returns false without throwing.
Example:
Definition at line 188 of file csv_row.hpp.
|
inlinenoexcept |
Convert with the same rules as try_get(), retaining the failure reason.
On failure, out is unchanged and error identifies the conversion failure.
Definition at line 197 of file csv_row.hpp.
| bool csv::CSVField::try_parse_decimal | ( | long double & | dVal, |
| const char | decimalSymbol = '.' |
||
| ) |
Attempts to parse a decimal (or integer) value using the given symbol, returning true if the value is numeric.
Definition at line 164 of file csv_row.cpp.
|
inline |
Parse a hexadecimal value, returning false if the value is not hex.
| T | An integral type (int, long, long long, etc.) |
Definition at line 222 of file csv_row.hpp.
|
inlinenoexcept |
Parse this field as a timestamp duration since the Unix epoch.
Definition at line 267 of file csv_row.hpp.
|
inlinenoexcept |
Parse this field as a std::chrono::system_clock time point.
Definition at line 279 of file csv_row.hpp.
|
noexcept |
Parse this field as Unix milliseconds.
Timestamp-classified values return their parsed epoch value. Integral values are treated as already being Unix milliseconds.
Definition at line 198 of file csv_row.cpp.
|
inlinenoexcept |
Return the type of the underlying CSV data.
Definition at line 345 of file csv_row.hpp.