Utility functions used by the library.
More...
#include <string_view>
#include <string>
#include <optional>
#include <algorithm>
#include <charconv>
Go to the source code of this file.
|
| std::string | Csv::cleanString (std::string_view view) |
| | Unescape a string - collapse every occurrence of 2 consecutive double-quotes to one.
|
| |
| constexpr std::size_t | Csv::getCleanStringSize (std::string_view uncollapsed_view) |
| | Get size of a cleaned-up string given the uncollapsed string.
|
| |
| template<typename Number > |
| std::optional< Number > | Csv::readNumberLocale (std::string_view cell) |
| | Try to read a numeric value from string data.
|
| |
| template<typename Number > |
| std::optional< Number > | Csv::readNumberNoLocale (std::string_view cell) |
| | Try to read a numeric value from string data.
|
| |
| template<typename Vector2D > |
| constexpr auto | Csv::vector2DValue (const Vector2D &values, std::size_t row, std::size_t column) |
| | A helper function to get an element of a 2D vector in less error-prone way.
|
| |
Utility functions used by the library.
◆ cleanString()
| std::string Csv::cleanString |
( |
std::string_view |
view | ) |
|
|
inline |
Unescape a string - collapse every occurrence of 2 consecutive double-quotes to one.
- Parameters
-
- Returns
- Unescaped string
◆ getCleanStringSize()
| constexpr std::size_t Csv::getCleanStringSize |
( |
std::string_view |
uncollapsed_view | ) |
|
|
inlineconstexpr |
Get size of a cleaned-up string given the uncollapsed string.
- Parameters
-
| uncollapsed_view | Input string |
- Returns
- Size of the cleaned-up string
◆ readNumberLocale()
template<typename Number >
| std::optional< Number > Csv::readNumberLocale |
( |
std::string_view |
cell | ) |
|
Try to read a numeric value from string data.
Unless the string data completely represents a serialized int/float/double/..., std::nullopt is returned.
- Note
- This function is locale-dependent.
- Template Parameters
-
| Number | Type of number to read, e.g. int, float, double, etc. |
- Parameters
-
| cell | String data to parse, with optional whitespace on one or both sides. |
- Returns
- Parsed number or
std::nullopt if parsing failed.
◆ readNumberNoLocale()
template<typename Number >
| std::optional< Number > Csv::readNumberNoLocale |
( |
std::string_view |
cell | ) |
|
Try to read a numeric value from string data.
Unless the string data completely represents a serialized int/float/double/..., std::nullopt is returned.
- Note
- This function is locale-independent.
-
This function is constexpr in C++23+ when parsing integral types.
- Template Parameters
-
| Number | Type of number to read, e.g. int, float, double, etc. |
- Parameters
-
| cell | String data to parse, with optional whitespace on one or both sides. |
- Returns
- Parsed number or
std::nullopt if parsing failed.
◆ vector2DValue()
template<typename Vector2D >
| constexpr auto Csv::vector2DValue |
( |
const Vector2D & |
values, |
|
|
std::size_t |
row, |
|
|
std::size_t |
column |
|
) |
| |
|
constexpr |
A helper function to get an element of a 2D vector in less error-prone way.
- Template Parameters
-
| Vector2D | A 2D vector type, deduced from the argument. |
- Parameters
-
| values | A vector of columns |
| row | 0-based row number |
| column | 0-based column number |
- Returns
- Value of Vector2D's innermost type