62 template<
typename BehaviorPolicy>
69 [[nodiscard]]
inline constexpr bool isEmpty()
const;
74 [[nodiscard]]
inline constexpr std::optional<double>
getDouble()
const;
82 bool* has_escaped_quotes =
nullptr)
const;
88 [[nodiscard]]
inline std::optional<std::string>
getCleanString()
const;
96 template<std::
size_t BufferSize>
111 std::string_view view;
112 bool has_escaped_quotes =
false;
138 template<
typename BehaviorPolicy>
145 [[nodiscard]]
inline bool isEmpty()
const;
150 [[nodiscard]]
inline std::optional<double>
getDouble()
const;
156 [[nodiscard]]
inline std::optional<std::string>
getString()
const;
189 template<
typename BehaviorPolicy>
191 CellTypeHint hint_ignored, BehaviorPolicy policy)
noexcept;
195 [[nodiscard]]
inline constexpr double getValue()
const;
199 double value_ = std::numeric_limits<double>::quiet_NaN();
220 template<
typename BehaviorPolicy>
228 bool* has_escaped_quotes =
nullptr) const noexcept;
242 template<std::
size_t BufferSize>
253 std::string_view value_;
256 bool has_escaped_quotes_ = false;
276 template<
typename BehaviorPolicy>
282 [[nodiscard]]
inline const std::string& getString()
const;
296template<
typename BehaviorPolicy>
298 [[maybe_unused]] BehaviorPolicy policy)
noexcept
301 case CellTypeHint::Empty:
305 case CellTypeHint::StringWithEscapedQuotes:
306 value_ =
String{cell,
true};
309 case CellTypeHint::StringWithoutEscapedQuotes:
310 value_ =
String{cell,
false};
313 case CellTypeHint::UnquotedData:
314 if (
auto double_value = BehaviorPolicy::template readNumber<double>(cell); double_value.has_value()) {
315 value_ = double_value.value();
317 value_ =
String{cell,
false};
327 if (std::holds_alternative<Empty>(value_)) {
328 return CellType::Empty;
330 if (std::holds_alternative<double>(value_)) {
331 return CellType::Double;
333 if (std::holds_alternative<String>(value_)) {
334 return CellType::String;
336 throw std::bad_variant_access();
343 return std::holds_alternative<Empty>(value_);
350 if (std::holds_alternative<double>(value_)) {
351 return std::get<double>(value_);
360 if (std::holds_alternative<String>(value_)) {
361 const auto& s = std::get<String>(value_);
362 if (has_escaped_quotes) {
363 *has_escaped_quotes = s.has_escaped_quotes;
374 if (std::holds_alternative<String>(value_)) {
375 const auto& s = std::get<String>(value_);
376 return s.has_escaped_quotes ?
cleanString(s.view) : std::string(s.view);
383template<std::
size_t BufferSize>
387 const auto& s = std::get<String>(value_);
396 const auto& s = std::get<String>(value_);
404template<
typename BehaviorPolicy>
408 case CellTypeHint::Empty:
412 case CellTypeHint::StringWithEscapedQuotes:
416 case CellTypeHint::StringWithoutEscapedQuotes:
417 value_ = std::string(cell);
420 case CellTypeHint::UnquotedData:
421 if (
auto double_value = BehaviorPolicy::template readNumber<double>(cell); double_value.has_value()) {
422 value_ = double_value.value();
424 value_ = std::string(cell);
434 if (std::holds_alternative<Empty>(value_)) {
435 return CellType::Empty;
437 if (std::holds_alternative<double>(value_)) {
438 return CellType::Double;
440 if (std::holds_alternative<std::string>(value_)) {
441 return CellType::String;
443 throw std::bad_variant_access();
450 return std::holds_alternative<Empty>(value_);
457 if (std::holds_alternative<double>(value_)) {
458 return std::get<double>(value_);
467 if (std::holds_alternative<std::string>(value_)) {
468 return std::get<std::string>(value_);
477template<
typename BehaviorPolicy>
479 [[maybe_unused]]
CellTypeHint hint_ignored, [[maybe_unused]] BehaviorPolicy policy)
noexcept
481 if (
auto double_value = BehaviorPolicy::template readNumber<double>(cell); double_value.has_value()) {
482 value_ = double_value.value();
497template<
typename BehaviorPolicy>
499 [[maybe_unused]] BehaviorPolicy policy) noexcept
501 has_escaped_quotes_(hint == CellTypeHint::StringWithEscapedQuotes)
508 if (has_escaped_quotes) {
509 *has_escaped_quotes = has_escaped_quotes_;
518 return has_escaped_quotes_ ?
cleanString(value_) : std::string(value_);
523template<std::
size_t BufferSize>
540template<
typename BehaviorPolicy>
542 [[maybe_unused]] BehaviorPolicy policy)
Data inside a single cell, stored as a value of double type.
Definition csv_cell.h:177
constexpr double getValue() const
Get the cell value if cell type is Double.
Definition csv_cell.h:488
constexpr CellDoubleValue()=default
Constructor, setting the value to std::numeric_limits<double>::quiet_NaN().
Data inside a single cell, potentially stored as a reference to the original data.
Definition csv_cell.h:51
constexpr CellStringBuffer< BufferSize > getCleanStringBuffer() const
Get a string buffer with collapsed consecutive double-quotes.
Definition csv_cell.h:384
constexpr std::optional< double > getDouble() const
Get the cell value as a double.
Definition csv_cell.h:348
constexpr CellReference()=default
Constructor, creates an Empty value.
constexpr CellType getType() const
Get data type.
Definition csv_cell.h:325
constexpr std::optional< std::string_view > getOriginalStringView(bool *has_escaped_quotes=nullptr) const
Get stored data reference as string_view to the original CSV data.
Definition csv_cell.h:358
constexpr std::size_t getRequiredBufferSize() const
Get required buffer size to use as getCleanStringBuffer()'s template argument.
Definition csv_cell.h:393
std::optional< std::string > getCleanString() const
Get stored cell data as std::string.
Definition csv_cell.h:372
constexpr bool isEmpty() const
Check whether the data is of CellType::Empty type.
Definition csv_cell.h:341
A helper class for compile-time buffer construction and string unescaping.
Definition csv_cell_string_buffer.h:29
String data inside a single cell, stored as a reference to the original data.
Definition csv_cell.h:209
std::string getCleanString()
Get stored cell reference a std::string.
Definition csv_cell.h:516
constexpr std::size_t getRequiredBufferSize() const
Get required buffer size to use as getCleanStringBuffer()'s template argument.
Definition csv_cell.h:531
constexpr CellStringReference()=default
Constructor, creates an empty string reference.
constexpr std::string_view getOriginalStringView(bool *has_escaped_quotes=nullptr) const noexcept
Get stored cell reference as string_view.
Definition csv_cell.h:506
constexpr CellStringBuffer< BufferSize > getCleanStringBuffer() const
Get a string buffer with collapsed consecutive double-quotes.
Definition csv_cell.h:524
A value of a cell.
Definition csv_cell.h:265
const std::string & getString() const
Get stored cell reference as string.
Definition csv_cell.h:548
CellStringValue()=default
Constructor.
Data inside a single cell, stored as a copy.
Definition csv_cell.h:127
std::optional< std::string > getString() const
Get stored cell value as std::string.
Definition csv_cell.h:465
CellType getType() const
Get cell type.
Definition csv_cell.h:432
bool isEmpty() const
Check whether the cell is of CellType::Empty type.
Definition csv_cell.h:448
std::optional< double > getDouble() const
Get the cell value if cell type is Double.
Definition csv_cell.h:455
CellValue()=default
Constructor, creates an Empty value.
CellTypeHint
Type hint associated with the cell to determine the type of the cell value.
Definition csv_cell.h:32
@ StringWithEscapedQuotes
Quoted or unquoted string with escaped quotes inside.
@ Empty
Empty data (no quotes, no whitespace).
@ StringWithoutEscapedQuotes
Quoted or unquoted string without any escaped quotes inside.
@ UnquotedData
Unquoted data, no escaped quotes inside.
CellType
Type of the cell value.
Definition csv_cell.h:41
Helper for compile-time buffer construction and string unescaping.
Utility functions used by the library.
constexpr std::size_t getCleanStringSize(std::string_view uncollapsed_view)
Get size of a cleaned-up string given the uncollapsed string.
Definition csv_util.h:104
std::string cleanString(std::string_view view)
Unescape a string - collapse every occurrence of 2 consecutive double-quotes to one.
Definition csv_util.h:88