Vince's CSV Parser
csv::CSVField Class Reference

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.
 
 operator std::string () const
 
template<typename T = std::string>
get ()
 Returns the value casted to the requested type, performing type checking before. More...
 
bool try_parse_hex (int &parsedValue)
 Parse a hexadecimal value, returning false if the value is not hex.
 
template<typename T >
CONSTEXPR_14 bool operator== (T other) const noexcept
 Compares the contents of this field to a numeric value. More...
 
CONSTEXPR csv::string_view get_sv () const noexcept
 Return a string view over the field's contents.
 
CONSTEXPR_14 bool is_null () noexcept
 Returns true if field is an empty string or string of whitespace characters.
 
CONSTEXPR_14 bool is_str () noexcept
 Returns true if field is a non-numeric, non-empty string.
 
CONSTEXPR_14 bool is_num () noexcept
 Returns true if field is an integer or float.
 
CONSTEXPR_14 bool is_int () noexcept
 Returns true if field is an integer.
 
CONSTEXPR_14 bool is_float () noexcept
 Returns true if field is a floating point value.
 
CONSTEXPR_14 DataType type () noexcept
 Return the type of the underlying CSV data.
 
template<>
CONSTEXPR_14 long double get ()
 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.
 

Detailed Description

Data type representing individual CSV values.

CSVFields can be obtained by using CSVRow::operator[]

Definition at line 143 of file csv_row.hpp.

Member Function Documentation

◆ get()

template<typename T = std::string>
T csv::CSVField::get ( )
inline

Returns the value casted to the requested type, performing type checking before.

Valid options for T
  • std::string or csv::string_view
  • signed integral types (signed char, short, int, long int, long long int)
  • floating point types (float, double, long double)
  • unsigned integers are not supported at this time, but may be in a later release
Invalid conversions
  • Converting non-numeric values to any numeric type
  • Converting floating point values to integers
  • Converting a large integer to a smaller type that will not hold it
Note
This method is capable of parsing scientific E-notation. See this page for more details.
Exceptions
std::runtime_errorThrown if an invalid conversion is performed.
Warning
Currently, conversions to floating point types are not checked for loss of precision
Any string_views returned are only guaranteed to be valid if the parent CSVRow is still alive. If you are concerned about object lifetimes, then grab a std::string or a numeric value.

Definition at line 180 of file csv_row.hpp.

◆ operator==()

template<typename T >
CONSTEXPR_14 bool csv::CSVField::operator== ( other) const
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.

Note
Floating point values are considered equal if they are within 0.000001 of each other.
Warning
Multiple numeric comparisons involving the same field can be done more efficiently by calling the CSVField::get<>() method.
See also
csv::CSVField::operator==(const char * other)
csv::CSVField::operator==(csv::string_view other)

Definition at line 234 of file csv_row.hpp.


The documentation for this class was generated from the following files: