mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 13:05:20 +01:00
Add [[nodiscard]] where fitting, update unit tests (#49)
This commit is contained in:
parent
809939d0e2
commit
f4bca3915f
@ -32,7 +32,7 @@ void assert_throw_on_error_not_defined() {
|
||||
"'throw_on_error' is enabled");
|
||||
}
|
||||
|
||||
inline void* strict_realloc(void* ptr, size_t size) {
|
||||
[[nodiscard]] inline void* strict_realloc(void* ptr, size_t size) {
|
||||
ptr = std::realloc(ptr, size);
|
||||
if (!ptr) {
|
||||
throw std::bad_alloc{};
|
||||
@ -42,14 +42,16 @@ inline void* strict_realloc(void* ptr, size_t size) {
|
||||
}
|
||||
|
||||
#if __unix__
|
||||
inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
|
||||
[[nodiscard]] inline ssize_t get_line_file(char*& lineptr, size_t& n,
|
||||
FILE* file) {
|
||||
return getline(&lineptr, &n, file);
|
||||
}
|
||||
#else
|
||||
|
||||
using ssize_t = intptr_t;
|
||||
|
||||
inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
|
||||
[[nodiscard]] inline ssize_t get_line_file(char*& lineptr, size_t& n,
|
||||
FILE* file) {
|
||||
std::array<char, get_line_initial_buffer_size> buff;
|
||||
|
||||
if (lineptr == nullptr || n < sizeof(buff)) {
|
||||
@ -85,8 +87,9 @@ inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
|
||||
|
||||
#endif
|
||||
|
||||
inline ssize_t get_line_buffer(char*& lineptr, size_t& n,
|
||||
const char* const csv_data_buffer, size_t csv_data_size,
|
||||
[[nodiscard]] inline ssize_t get_line_buffer(char*& lineptr, size_t& n,
|
||||
const char* const csv_data_buffer,
|
||||
size_t csv_data_size,
|
||||
size_t& curr_char) {
|
||||
if (curr_char >= csv_data_size) {
|
||||
return -1;
|
||||
@ -122,10 +125,10 @@ inline ssize_t get_line_buffer(char*& lineptr, size_t& n,
|
||||
return line_used;
|
||||
}
|
||||
|
||||
inline std::tuple<ssize_t, bool> get_line(char*& buffer, size_t& buffer_size,
|
||||
FILE* file,
|
||||
const char* const csv_data_buffer,
|
||||
size_t csv_data_size, size_t& curr_char) {
|
||||
[[nodiscard]] inline std::tuple<ssize_t, bool> get_line(
|
||||
char*& buffer, size_t& buffer_size, FILE* file,
|
||||
const char* const csv_data_buffer, size_t csv_data_size,
|
||||
size_t& curr_char) {
|
||||
ssize_t ssize = 0;
|
||||
if (file) {
|
||||
ssize = get_line_file(buffer, buffer_size, file);
|
||||
|
@ -110,15 +110,15 @@ public:
|
||||
// parses line with given delimiter, returns a 'T' object created with
|
||||
// extracted values of type 'Ts'
|
||||
template <typename T, typename... Ts>
|
||||
T convert_object(line_ptr_type line,
|
||||
const std::string& delim = default_delimiter) {
|
||||
[[nodiscard]] T convert_object(
|
||||
line_ptr_type line, const std::string& delim = default_delimiter) {
|
||||
return to_object<T>(convert<Ts...>(line, delim));
|
||||
}
|
||||
|
||||
// parses line with given delimiter, returns tuple of objects with
|
||||
// extracted values of type 'Ts'
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<Ts...> convert(
|
||||
[[nodiscard]] no_void_validator_tup_t<Ts...> convert(
|
||||
line_ptr_type line, const std::string& delim = default_delimiter) {
|
||||
split(line, delim);
|
||||
if (splitter_.valid()) {
|
||||
@ -131,13 +131,13 @@ public:
|
||||
|
||||
// parses already split line, returns 'T' object with extracted values
|
||||
template <typename T, typename... Ts>
|
||||
T convert_object(const split_data& elems) {
|
||||
[[nodiscard]] T convert_object(const split_data& elems) {
|
||||
return to_object<T>(convert<Ts...>(elems));
|
||||
}
|
||||
|
||||
// same as above, but uses cached split line
|
||||
template <typename T, typename... Ts>
|
||||
T convert_object() {
|
||||
[[nodiscard]] T convert_object() {
|
||||
return to_object<T>(convert<Ts...>());
|
||||
}
|
||||
|
||||
@ -146,7 +146,8 @@ public:
|
||||
// one argument is given which is a class which has a tied
|
||||
// method which returns a tuple, returns that type
|
||||
template <typename T, typename... Ts>
|
||||
no_void_validator_tup_t<T, Ts...> convert(const split_data& elems) {
|
||||
[[nodiscard]] no_void_validator_tup_t<T, Ts...> convert(
|
||||
const split_data& elems) {
|
||||
if constexpr (sizeof...(Ts) == 0 && is_instance_of_v<std::tuple, T>) {
|
||||
return convert_impl(elems, static_cast<T*>(nullptr));
|
||||
} else if constexpr (tied_class_v<T, Ts...>) {
|
||||
@ -162,11 +163,11 @@ public:
|
||||
|
||||
// same as above, but uses cached split line
|
||||
template <typename T, typename... Ts>
|
||||
no_void_validator_tup_t<T, Ts...> convert() {
|
||||
[[nodiscard]] no_void_validator_tup_t<T, Ts...> convert() {
|
||||
return convert<T, Ts...>(splitter_.split_data_);
|
||||
}
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
if constexpr (string_error) {
|
||||
return error_.empty();
|
||||
} else if constexpr (throw_on_error) {
|
||||
@ -176,12 +177,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& error_msg() const {
|
||||
[[nodiscard]] const std::string& error_msg() const {
|
||||
assert_string_error_defined<string_error>();
|
||||
return error_;
|
||||
}
|
||||
|
||||
bool unterminated_quote() const {
|
||||
[[nodiscard]] bool unterminated_quote() const {
|
||||
return splitter_.unterminated_quote();
|
||||
}
|
||||
|
||||
@ -207,7 +208,7 @@ private:
|
||||
return splitter_.resplit(new_line, new_size, delim);
|
||||
}
|
||||
|
||||
size_t size_shifted() {
|
||||
[[nodiscard]] size_t size_shifted() {
|
||||
return splitter_.size_shifted();
|
||||
}
|
||||
|
||||
@ -223,7 +224,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
std::string error_sufix(const string_range msg, size_t pos) const {
|
||||
[[nodiscard]] std::string error_sufix(const string_range msg,
|
||||
size_t pos) const {
|
||||
constexpr static auto reserve_size = 32;
|
||||
std::string error;
|
||||
error.reserve(reserve_size);
|
||||
@ -351,7 +353,8 @@ private:
|
||||
////////////////
|
||||
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<Ts...> convert_impl(const split_data& elems) {
|
||||
[[nodiscard]] no_void_validator_tup_t<Ts...> convert_impl(
|
||||
const split_data& elems) {
|
||||
clear_error();
|
||||
|
||||
if (!splitter_.valid()) {
|
||||
@ -382,7 +385,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||
[[nodiscard]] no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||
const split_data& elems, const std::tuple<Ts...>*) {
|
||||
return convert_impl<Ts...>(elems);
|
||||
}
|
||||
@ -391,11 +394,11 @@ private:
|
||||
// column mapping
|
||||
////////////////
|
||||
|
||||
bool columns_mapped() const {
|
||||
[[nodiscard]] bool columns_mapped() const {
|
||||
return !column_mappings_.empty();
|
||||
}
|
||||
|
||||
size_t column_position(size_t tuple_position) const {
|
||||
[[nodiscard]] size_t column_position(size_t tuple_position) const {
|
||||
if (!columns_mapped()) {
|
||||
return tuple_position;
|
||||
}
|
||||
@ -426,7 +429,7 @@ private:
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<T, std::string>) {
|
||||
extract(msg.first, msg.second, dst);
|
||||
static_cast<void>(extract(msg.first, msg.second, dst));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -472,7 +475,8 @@ private:
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<Ts...> extract_tuple(const split_data& elems) {
|
||||
[[nodiscard]] no_void_validator_tup_t<Ts...> extract_tuple(
|
||||
const split_data& elems) {
|
||||
static_assert(!all_of_v<std::is_void, Ts...>,
|
||||
"at least one parameter must be non void");
|
||||
no_void_validator_tup_t<Ts...> ret{};
|
||||
|
@ -12,10 +12,10 @@ class exception : public std::exception {
|
||||
std::string msg_;
|
||||
|
||||
public:
|
||||
exception(std::string msg): msg_{std::move(msg)} {
|
||||
exception(std::string msg) : msg_{std::move(msg)} {
|
||||
}
|
||||
|
||||
char const* what() const noexcept override {
|
||||
[[nodiscard]] char const* what() const noexcept override {
|
||||
return msg_.c_str();
|
||||
}
|
||||
};
|
||||
|
@ -13,8 +13,8 @@
|
||||
#include <fast_float/fast_float.h>
|
||||
#else
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
namespace ss {
|
||||
@ -26,8 +26,8 @@ namespace ss {
|
||||
#ifndef SSP_DISABLE_FAST_FLOAT
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>>
|
||||
to_num(const char* const begin, const char* const end) {
|
||||
T ret;
|
||||
auto [ptr, ec] = fast_float::from_chars(begin, end, ret);
|
||||
|
||||
@ -40,8 +40,8 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
#else
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>>
|
||||
to_num(const char* const begin, const char* const end) {
|
||||
static_assert(!std::is_same_v<T, long double>,
|
||||
"Conversion to long double is disabled");
|
||||
|
||||
@ -114,7 +114,7 @@ using int8 = numeric_wrapper<int8_t>;
|
||||
using uint8 = numeric_wrapper<uint8_t>;
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_integral_v<T>, std::optional<T>> to_num(
|
||||
[[nodiscard]] std::enable_if_t<std::is_integral_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
T ret;
|
||||
auto [ptr, ec] = std::from_chars(begin, end, ret);
|
||||
@ -126,8 +126,9 @@ std::enable_if_t<std::is_integral_v<T>, std::optional<T>> to_num(
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<is_instance_of_v<numeric_wrapper, T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
[[nodiscard]] std::enable_if_t<is_instance_of_v<numeric_wrapper, T>,
|
||||
std::optional<T>>
|
||||
to_num(const char* const begin, const char* const end) {
|
||||
T ret;
|
||||
auto [ptr, ec] = std::from_chars(begin, end, ret.value);
|
||||
|
||||
@ -149,7 +150,8 @@ struct unsupported_type {
|
||||
} /* namespace errors */
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<!std::is_integral_v<T> && !std::is_floating_point_v<T> &&
|
||||
[[nodiscard]] std::enable_if_t<!std::is_integral_v<T> &&
|
||||
!std::is_floating_point_v<T> &&
|
||||
!is_instance_of_v<std::optional, T> &&
|
||||
!is_instance_of_v<std::variant, T> &&
|
||||
!is_instance_of_v<numeric_wrapper, T>,
|
||||
@ -161,7 +163,8 @@ extract(const char*, const char*, T&) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_integral_v<T> || std::is_floating_point_v<T> ||
|
||||
[[nodiscard]] std::enable_if_t<std::is_integral_v<T> ||
|
||||
std::is_floating_point_v<T> ||
|
||||
is_instance_of_v<numeric_wrapper, T>,
|
||||
bool>
|
||||
extract(const char* begin, const char* end, T& value) {
|
||||
@ -174,8 +177,8 @@ extract(const char* begin, const char* end, T& value) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<is_instance_of_v<std::optional, T>, bool> extract(
|
||||
const char* begin, const char* end, T& value) {
|
||||
[[nodiscard]] std::enable_if_t<is_instance_of_v<std::optional, T>, bool>
|
||||
extract(const char* begin, const char* end, T& value) {
|
||||
typename T::value_type raw_value;
|
||||
if (extract(begin, end, raw_value)) {
|
||||
value = raw_value;
|
||||
@ -186,7 +189,8 @@ std::enable_if_t<is_instance_of_v<std::optional, T>, bool> extract(
|
||||
}
|
||||
|
||||
template <typename T, size_t I>
|
||||
bool extract_variant(const char* begin, const char* end, T& value) {
|
||||
[[nodiscard]] bool extract_variant(const char* begin, const char* end,
|
||||
T& value) {
|
||||
using IthType = std::variant_alternative_t<I, std::decay_t<T>>;
|
||||
IthType ithValue;
|
||||
if (extract<IthType>(begin, end, ithValue)) {
|
||||
@ -199,7 +203,7 @@ bool extract_variant(const char* begin, const char* end, T& value) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<is_instance_of_v<std::variant, T>, bool> extract(
|
||||
[[nodiscard]] std::enable_if_t<is_instance_of_v<std::variant, T>, bool> extract(
|
||||
const char* begin, const char* end, T& value) {
|
||||
return extract_variant<T, 0>(begin, end, value);
|
||||
}
|
||||
@ -209,7 +213,8 @@ std::enable_if_t<is_instance_of_v<std::variant, T>, bool> extract(
|
||||
////////////////
|
||||
|
||||
template <>
|
||||
inline bool extract(const char* begin, const char* end, bool& value) {
|
||||
[[nodiscard]] inline bool extract(const char* begin, const char* end,
|
||||
bool& value) {
|
||||
if (end == begin + 1) {
|
||||
if (*begin == '1') {
|
||||
value = true;
|
||||
@ -236,19 +241,21 @@ inline bool extract(const char* begin, const char* end, bool& value) {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool extract(const char* begin, const char* end, char& value) {
|
||||
[[nodiscard]] inline bool extract(const char* begin, const char* end,
|
||||
char& value) {
|
||||
value = *begin;
|
||||
return (end == begin + 1);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool extract(const char* begin, const char* end, std::string& value) {
|
||||
[[nodiscard]] inline bool extract(const char* begin, const char* end,
|
||||
std::string& value) {
|
||||
value = std::string{begin, end};
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool extract(const char* begin, const char* end,
|
||||
[[nodiscard]] inline bool extract(const char* begin, const char* end,
|
||||
std::string_view& value) {
|
||||
value = std::string_view{begin, static_cast<size_t>(end - begin)};
|
||||
return true;
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
parser(const parser& other) = delete;
|
||||
parser& operator=(const parser& other) = delete;
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
if constexpr (string_error) {
|
||||
return error_.empty();
|
||||
} else if constexpr (throw_on_error) {
|
||||
@ -85,12 +85,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& error_msg() const {
|
||||
[[nodiscard]] const std::string& error_msg() const {
|
||||
assert_string_error_defined<string_error>();
|
||||
return error_;
|
||||
}
|
||||
|
||||
bool eof() const {
|
||||
[[nodiscard]] bool eof() const {
|
||||
return eof_;
|
||||
}
|
||||
|
||||
@ -99,21 +99,21 @@ public:
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
T get_object() {
|
||||
[[nodiscard]] T get_object() {
|
||||
return to_object<T>(get_next<Ts...>());
|
||||
}
|
||||
|
||||
size_t line() const {
|
||||
[[nodiscard]] size_t line() const {
|
||||
return reader_.line_number_ > 0 ? reader_.line_number_ - 1
|
||||
: reader_.line_number_;
|
||||
}
|
||||
|
||||
size_t position() const {
|
||||
[[nodiscard]] size_t position() const {
|
||||
return reader_.chars_read_;
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
no_void_validator_tup_t<T, Ts...> get_next() {
|
||||
[[nodiscard]] no_void_validator_tup_t<T, Ts...> get_next() {
|
||||
std::optional<std::string> error;
|
||||
|
||||
if (!eof_) {
|
||||
@ -164,12 +164,12 @@ public:
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string raw_header() const {
|
||||
[[nodiscard]] std::string raw_header() const {
|
||||
assert_ignore_header_not_defined();
|
||||
return raw_header_;
|
||||
}
|
||||
|
||||
std::vector<std::string> header() {
|
||||
[[nodiscard]] std::vector<std::string> header() {
|
||||
assert_ignore_header_not_defined();
|
||||
clear_error();
|
||||
|
||||
@ -188,7 +188,7 @@ public:
|
||||
return split_header;
|
||||
}
|
||||
|
||||
bool field_exists(const std::string& field) {
|
||||
[[nodiscard]] bool field_exists(const std::string& field) {
|
||||
assert_ignore_header_not_defined();
|
||||
clear_error();
|
||||
|
||||
@ -273,11 +273,11 @@ public:
|
||||
iterator& operator=(const iterator& other) = delete;
|
||||
iterator& operator=(iterator&& other) = delete;
|
||||
|
||||
value& operator*() {
|
||||
[[nodiscard]] value& operator*() {
|
||||
return value_;
|
||||
}
|
||||
|
||||
value* operator->() {
|
||||
[[nodiscard]] value* operator->() {
|
||||
return &value_;
|
||||
}
|
||||
|
||||
@ -302,13 +302,15 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
friend bool operator==(const iterator& lhs, const iterator& rhs) {
|
||||
[[nodiscard]] friend bool operator==(const iterator& lhs,
|
||||
const iterator& rhs) {
|
||||
return (lhs.parser_ == nullptr && rhs.parser_ == nullptr) ||
|
||||
(lhs.parser_ == rhs.parser_ &&
|
||||
&lhs.value_ == &rhs.value_);
|
||||
}
|
||||
|
||||
friend bool operator!=(const iterator& lhs, const iterator& rhs) {
|
||||
[[nodiscard]] friend bool operator!=(const iterator& lhs,
|
||||
const iterator& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
@ -320,11 +322,11 @@ public:
|
||||
iterable(parser<Options...>* parser) : parser_{parser} {
|
||||
}
|
||||
|
||||
iterator begin() {
|
||||
[[nodiscard]] iterator begin() {
|
||||
return ++iterator{parser_};
|
||||
}
|
||||
|
||||
iterator end() {
|
||||
[[nodiscard]] iterator end() {
|
||||
return iterator{};
|
||||
}
|
||||
|
||||
@ -333,12 +335,12 @@ public:
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
auto iterate() {
|
||||
[[nodiscard]] auto iterate() {
|
||||
return iterable<false, Ts...>{this};
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
auto iterate_object() {
|
||||
[[nodiscard]] auto iterate_object() {
|
||||
return iterable<true, Ts...>{this};
|
||||
}
|
||||
|
||||
@ -376,7 +378,7 @@ public:
|
||||
return composite_with(std::move(value));
|
||||
}
|
||||
|
||||
std::tuple<Ts...> values() {
|
||||
[[nodiscard]] std::tuple<Ts...> values() {
|
||||
return values_;
|
||||
}
|
||||
|
||||
@ -399,7 +401,7 @@ public:
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
composite<Ts..., T> composite_with(T&& new_value) {
|
||||
[[nodiscard]] composite<Ts..., T> composite_with(T&& new_value) {
|
||||
auto merged_values =
|
||||
std::tuple_cat(std::move(values_),
|
||||
std::tuple<T>{parser_.valid()
|
||||
@ -429,7 +431,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename U, typename... Us>
|
||||
no_void_validator_tup_t<U, Us...> try_same() {
|
||||
[[nodiscard]] no_void_validator_tup_t<U, Us...> try_same() {
|
||||
parser_.clear_error();
|
||||
auto value =
|
||||
parser_.reader_.converter_.template convert<U, Us...>();
|
||||
@ -450,8 +452,8 @@ public:
|
||||
// tries to convert a line and returns a composite which is
|
||||
// able to try additional conversions in case of failure
|
||||
template <typename... Ts, typename Fun = none>
|
||||
composite<std::optional<no_void_validator_tup_t<Ts...>>> try_next(
|
||||
Fun&& fun = none{}) {
|
||||
[[nodiscard]] composite<std::optional<no_void_validator_tup_t<Ts...>>>
|
||||
try_next(Fun&& fun = none{}) {
|
||||
assert_throw_on_error_not_defined<throw_on_error>();
|
||||
using Ret = no_void_validator_tup_t<Ts...>;
|
||||
return try_invoke_and_make_composite<
|
||||
@ -461,7 +463,7 @@ public:
|
||||
// identical to try_next but returns composite with object instead of a
|
||||
// tuple
|
||||
template <typename T, typename... Ts, typename Fun = none>
|
||||
composite<std::optional<T>> try_object(Fun&& fun = none{}) {
|
||||
[[nodiscard]] composite<std::optional<T>> try_object(Fun&& fun = none{}) {
|
||||
assert_throw_on_error_not_defined<throw_on_error>();
|
||||
return try_invoke_and_make_composite<
|
||||
std::optional<T>>(get_object<T, Ts...>(), std::forward<Fun>(fun));
|
||||
@ -512,7 +514,8 @@ private:
|
||||
}
|
||||
|
||||
template <typename T, typename Fun = none>
|
||||
composite<T> try_invoke_and_make_composite(T&& value, Fun&& fun) {
|
||||
[[nodiscard]] composite<T> try_invoke_and_make_composite(T&& value,
|
||||
Fun&& fun) {
|
||||
if (valid()) {
|
||||
try_invoke(*value, std::forward<Fun>(fun));
|
||||
}
|
||||
@ -528,7 +531,8 @@ private:
|
||||
"cannot use this method when 'ignore_header' is defined");
|
||||
}
|
||||
|
||||
bool strict_split(header_splitter& splitter, std::string& header) {
|
||||
[[nodiscard]] bool strict_split(header_splitter& splitter,
|
||||
std::string& header) {
|
||||
if (header.empty()) {
|
||||
return false;
|
||||
}
|
||||
@ -575,7 +579,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<size_t> header_index(const std::string& field) {
|
||||
[[nodiscard]] std::optional<size_t> header_index(const std::string& field) {
|
||||
auto it = std::find(header_.begin(), header_.end(), field);
|
||||
|
||||
if (it == header_.end()) {
|
||||
@ -846,7 +850,7 @@ private:
|
||||
reader& operator=(const reader& other) = delete;
|
||||
|
||||
// read next line each time in order to set eof_
|
||||
bool read_next() {
|
||||
[[nodiscard]] bool read_next() {
|
||||
next_line_converter_.clear_error();
|
||||
size_t size = 0;
|
||||
while (size == 0) {
|
||||
@ -938,7 +942,7 @@ private:
|
||||
std::swap(converter_, next_line_converter_);
|
||||
}
|
||||
|
||||
bool multiline_limit_reached(size_t& limit) {
|
||||
[[nodiscard]] bool multiline_limit_reached(size_t& limit) {
|
||||
if constexpr (multiline::size > 0) {
|
||||
if (limit++ >= multiline::size) {
|
||||
next_line_converter_.handle_error_multiline_limit_reached();
|
||||
@ -948,7 +952,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool escaped_eol(size_t size) {
|
||||
[[nodiscard]] bool escaped_eol(size_t size) {
|
||||
const char* curr = nullptr;
|
||||
for (curr = next_line_buffer_ + size - 1;
|
||||
curr >= next_line_buffer_ &&
|
||||
@ -958,7 +962,7 @@ private:
|
||||
return (next_line_buffer_ - curr + size) % 2 == 0;
|
||||
}
|
||||
|
||||
bool unterminated_quote() {
|
||||
[[nodiscard]] bool unterminated_quote() {
|
||||
return next_line_converter_.unterminated_quote();
|
||||
}
|
||||
|
||||
@ -973,7 +977,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
size_t remove_eol(char*& buffer, size_t ssize) {
|
||||
[[nodiscard]] size_t remove_eol(char*& buffer, size_t ssize) {
|
||||
if (buffer[ssize - 1] != '\n') {
|
||||
crlf_ = false;
|
||||
return ssize;
|
||||
@ -1003,7 +1007,8 @@ private:
|
||||
first_size += second_size;
|
||||
}
|
||||
|
||||
bool append_next_line_to_buffer(char*& buffer, size_t& line_size,
|
||||
[[nodiscard]] bool append_next_line_to_buffer(char*& buffer,
|
||||
size_t& line_size,
|
||||
size_t buffer_size) {
|
||||
undo_remove_eol(buffer, line_size, buffer_size);
|
||||
|
||||
@ -1023,7 +1028,7 @@ private:
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string get_buffer() {
|
||||
[[nodiscard]] std::string get_buffer() {
|
||||
return std::string{next_line_buffer_, next_line_size_};
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ template <typename T, auto... Values>
|
||||
struct ax {
|
||||
private:
|
||||
template <auto X, auto... Xs>
|
||||
bool ss_valid_impl(const T& x) const {
|
||||
[[nodiscard]] bool ss_valid_impl(const T& x) const {
|
||||
if constexpr (sizeof...(Xs) != 0) {
|
||||
return x != X && ss_valid_impl<Xs...>(x);
|
||||
}
|
||||
@ -18,11 +18,11 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return ss_valid_impl<Values...>(value);
|
||||
}
|
||||
|
||||
const char* error() const {
|
||||
[[nodiscard]] const char* error() const {
|
||||
return "value excluded";
|
||||
}
|
||||
};
|
||||
@ -35,7 +35,7 @@ template <typename T, auto... Values>
|
||||
struct nx {
|
||||
private:
|
||||
template <auto X, auto... Xs>
|
||||
bool ss_valid_impl(const T& x) const {
|
||||
[[nodiscard]] bool ss_valid_impl(const T& x) const {
|
||||
if constexpr (sizeof...(Xs) != 0) {
|
||||
return x == X || ss_valid_impl<Xs...>(x);
|
||||
}
|
||||
@ -43,11 +43,11 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return ss_valid_impl<Values...>(value);
|
||||
}
|
||||
|
||||
const char* error() const {
|
||||
[[nodiscard]] const char* error() const {
|
||||
return "value excluded";
|
||||
}
|
||||
};
|
||||
@ -61,28 +61,28 @@ public:
|
||||
|
||||
template <typename T, auto N>
|
||||
struct gt {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value > N;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, auto N>
|
||||
struct gte {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value >= N;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, auto N>
|
||||
struct lt {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value < N;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, auto N>
|
||||
struct lte {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value <= N;
|
||||
}
|
||||
};
|
||||
@ -93,7 +93,7 @@ struct lte {
|
||||
|
||||
template <typename T, auto Min, auto Max>
|
||||
struct ir {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value >= Min && value <= Max;
|
||||
}
|
||||
};
|
||||
@ -104,7 +104,7 @@ struct ir {
|
||||
|
||||
template <typename T, auto Min, auto Max>
|
||||
struct oor {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value < Min || value > Max;
|
||||
}
|
||||
};
|
||||
@ -115,11 +115,11 @@ struct oor {
|
||||
|
||||
template <typename T>
|
||||
struct ne {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return !value.empty();
|
||||
}
|
||||
|
||||
const char* error() const {
|
||||
[[nodiscard]] const char* error() const {
|
||||
return "empty field";
|
||||
}
|
||||
};
|
||||
|
@ -28,7 +28,7 @@ private:
|
||||
public:
|
||||
using line_ptr_type = std::conditional_t<is_const_line, const char*, char*>;
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
if constexpr (string_error) {
|
||||
return error_.empty();
|
||||
} else if constexpr (throw_on_error) {
|
||||
@ -38,12 +38,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& error_msg() const {
|
||||
[[nodiscard]] const std::string& error_msg() const {
|
||||
assert_string_error_defined<string_error>();
|
||||
return error_;
|
||||
}
|
||||
|
||||
bool unterminated_quote() const {
|
||||
[[nodiscard]] bool unterminated_quote() const {
|
||||
return unterminated_quote_;
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ private:
|
||||
////////////////
|
||||
|
||||
// number of characters the end of line is shifted backwards
|
||||
size_t size_shifted() const {
|
||||
[[nodiscard]] size_t size_shifted() const {
|
||||
return escaped_;
|
||||
}
|
||||
|
||||
@ -192,19 +192,19 @@ private:
|
||||
// matching
|
||||
////////////////
|
||||
|
||||
bool match(const char* const curr, char delim) {
|
||||
[[nodiscard]] bool match(const char* const curr, char delim) {
|
||||
return *curr == delim;
|
||||
};
|
||||
|
||||
bool match(const char* const curr, const std::string& delim) {
|
||||
[[nodiscard]] bool match(const char* const curr, const std::string& delim) {
|
||||
return std::strncmp(curr, delim.c_str(), delim.size()) == 0;
|
||||
};
|
||||
|
||||
size_t delimiter_size(char) {
|
||||
[[nodiscard]] size_t delimiter_size(char) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t delimiter_size(const std::string& delim) {
|
||||
[[nodiscard]] size_t delimiter_size(const std::string& delim) {
|
||||
return delim.size();
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename Delim>
|
||||
std::tuple<size_t, bool> match_delimiter(line_ptr_type begin,
|
||||
[[nodiscard]] std::tuple<size_t, bool> match_delimiter(line_ptr_type begin,
|
||||
const Delim& delim) {
|
||||
line_ptr_type end = begin;
|
||||
|
||||
|
@ -366,12 +366,12 @@ constexpr bool is_instance_of_v = is_instance_of<Template, Ts...>::value;
|
||||
////////////////
|
||||
|
||||
template <class T, std::size_t... Is, class U>
|
||||
T to_object_impl(std::index_sequence<Is...>, U&& data) {
|
||||
[[nodiscard]] T to_object_impl(std::index_sequence<Is...>, U&& data) {
|
||||
return {std::get<Is>(std::forward<U>(data))...};
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
T to_object(U&& data) {
|
||||
[[nodiscard]] T to_object(U&& data) {
|
||||
using NoRefU = std::decay_t<U>;
|
||||
if constexpr (is_instance_of_v<std::tuple, NoRefU>) {
|
||||
return to_object_impl<
|
||||
|
229
ssp.hpp
229
ssp.hpp
@ -381,12 +381,12 @@ constexpr bool is_instance_of_v = is_instance_of<Template, Ts...>::value;
|
||||
////////////////
|
||||
|
||||
template <class T, std::size_t... Is, class U>
|
||||
T to_object_impl(std::index_sequence<Is...>, U&& data) {
|
||||
[[nodiscard]] T to_object_impl(std::index_sequence<Is...>, U&& data) {
|
||||
return {std::get<Is>(std::forward<U>(data))...};
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
T to_object(U&& data) {
|
||||
[[nodiscard]] T to_object(U&& data) {
|
||||
using NoRefU = std::decay_t<U>;
|
||||
if constexpr (is_instance_of_v<std::tuple, NoRefU>) {
|
||||
return to_object_impl<
|
||||
@ -409,10 +409,10 @@ class exception : public std::exception {
|
||||
std::string msg_;
|
||||
|
||||
public:
|
||||
exception(std::string msg): msg_{std::move(msg)} {
|
||||
exception(std::string msg) : msg_{std::move(msg)} {
|
||||
}
|
||||
|
||||
char const* what() const noexcept override {
|
||||
[[nodiscard]] char const* what() const noexcept override {
|
||||
return msg_.c_str();
|
||||
}
|
||||
};
|
||||
@ -505,7 +505,7 @@ template <typename T, auto... Values>
|
||||
struct ax {
|
||||
private:
|
||||
template <auto X, auto... Xs>
|
||||
bool ss_valid_impl(const T& x) const {
|
||||
[[nodiscard]] bool ss_valid_impl(const T& x) const {
|
||||
if constexpr (sizeof...(Xs) != 0) {
|
||||
return x != X && ss_valid_impl<Xs...>(x);
|
||||
}
|
||||
@ -513,11 +513,11 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return ss_valid_impl<Values...>(value);
|
||||
}
|
||||
|
||||
const char* error() const {
|
||||
[[nodiscard]] const char* error() const {
|
||||
return "value excluded";
|
||||
}
|
||||
};
|
||||
@ -530,7 +530,7 @@ template <typename T, auto... Values>
|
||||
struct nx {
|
||||
private:
|
||||
template <auto X, auto... Xs>
|
||||
bool ss_valid_impl(const T& x) const {
|
||||
[[nodiscard]] bool ss_valid_impl(const T& x) const {
|
||||
if constexpr (sizeof...(Xs) != 0) {
|
||||
return x == X || ss_valid_impl<Xs...>(x);
|
||||
}
|
||||
@ -538,11 +538,11 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return ss_valid_impl<Values...>(value);
|
||||
}
|
||||
|
||||
const char* error() const {
|
||||
[[nodiscard]] const char* error() const {
|
||||
return "value excluded";
|
||||
}
|
||||
};
|
||||
@ -556,28 +556,28 @@ public:
|
||||
|
||||
template <typename T, auto N>
|
||||
struct gt {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value > N;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, auto N>
|
||||
struct gte {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value >= N;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, auto N>
|
||||
struct lt {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value < N;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, auto N>
|
||||
struct lte {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value <= N;
|
||||
}
|
||||
};
|
||||
@ -588,7 +588,7 @@ struct lte {
|
||||
|
||||
template <typename T, auto Min, auto Max>
|
||||
struct ir {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value >= Min && value <= Max;
|
||||
}
|
||||
};
|
||||
@ -599,7 +599,7 @@ struct ir {
|
||||
|
||||
template <typename T, auto Min, auto Max>
|
||||
struct oor {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return value < Min || value > Max;
|
||||
}
|
||||
};
|
||||
@ -610,11 +610,11 @@ struct oor {
|
||||
|
||||
template <typename T>
|
||||
struct ne {
|
||||
bool ss_valid(const T& value) const {
|
||||
[[nodiscard]] bool ss_valid(const T& value) const {
|
||||
return !value.empty();
|
||||
}
|
||||
|
||||
const char* error() const {
|
||||
[[nodiscard]] const char* error() const {
|
||||
return "empty field";
|
||||
}
|
||||
};
|
||||
@ -648,7 +648,7 @@ void assert_throw_on_error_not_defined() {
|
||||
"'throw_on_error' is enabled");
|
||||
}
|
||||
|
||||
inline void* strict_realloc(void* ptr, size_t size) {
|
||||
[[nodiscard]] inline void* strict_realloc(void* ptr, size_t size) {
|
||||
ptr = std::realloc(ptr, size);
|
||||
if (!ptr) {
|
||||
throw std::bad_alloc{};
|
||||
@ -658,14 +658,16 @@ inline void* strict_realloc(void* ptr, size_t size) {
|
||||
}
|
||||
|
||||
#if __unix__
|
||||
inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
|
||||
[[nodiscard]] inline ssize_t get_line_file(char*& lineptr, size_t& n,
|
||||
FILE* file) {
|
||||
return getline(&lineptr, &n, file);
|
||||
}
|
||||
#else
|
||||
|
||||
using ssize_t = intptr_t;
|
||||
|
||||
inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
|
||||
[[nodiscard]] inline ssize_t get_line_file(char*& lineptr, size_t& n,
|
||||
FILE* file) {
|
||||
std::array<char, get_line_initial_buffer_size> buff;
|
||||
|
||||
if (lineptr == nullptr || n < sizeof(buff)) {
|
||||
@ -701,8 +703,9 @@ inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
|
||||
|
||||
#endif
|
||||
|
||||
inline ssize_t get_line_buffer(char*& lineptr, size_t& n,
|
||||
const char* const csv_data_buffer, size_t csv_data_size,
|
||||
[[nodiscard]] inline ssize_t get_line_buffer(char*& lineptr, size_t& n,
|
||||
const char* const csv_data_buffer,
|
||||
size_t csv_data_size,
|
||||
size_t& curr_char) {
|
||||
if (curr_char >= csv_data_size) {
|
||||
return -1;
|
||||
@ -738,10 +741,10 @@ inline ssize_t get_line_buffer(char*& lineptr, size_t& n,
|
||||
return line_used;
|
||||
}
|
||||
|
||||
inline std::tuple<ssize_t, bool> get_line(char*& buffer, size_t& buffer_size,
|
||||
FILE* file,
|
||||
const char* const csv_data_buffer,
|
||||
size_t csv_data_size, size_t& curr_char) {
|
||||
[[nodiscard]] inline std::tuple<ssize_t, bool> get_line(
|
||||
char*& buffer, size_t& buffer_size, FILE* file,
|
||||
const char* const csv_data_buffer, size_t csv_data_size,
|
||||
size_t& curr_char) {
|
||||
ssize_t ssize = 0;
|
||||
if (file) {
|
||||
ssize = get_line_file(buffer, buffer_size, file);
|
||||
@ -1079,7 +1082,7 @@ private:
|
||||
public:
|
||||
using line_ptr_type = std::conditional_t<is_const_line, const char*, char*>;
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
if constexpr (string_error) {
|
||||
return error_.empty();
|
||||
} else if constexpr (throw_on_error) {
|
||||
@ -1089,12 +1092,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& error_msg() const {
|
||||
[[nodiscard]] const std::string& error_msg() const {
|
||||
assert_string_error_defined<string_error>();
|
||||
return error_;
|
||||
}
|
||||
|
||||
bool unterminated_quote() const {
|
||||
[[nodiscard]] bool unterminated_quote() const {
|
||||
return unterminated_quote_;
|
||||
}
|
||||
|
||||
@ -1112,7 +1115,7 @@ private:
|
||||
////////////////
|
||||
|
||||
// number of characters the end of line is shifted backwards
|
||||
size_t size_shifted() const {
|
||||
[[nodiscard]] size_t size_shifted() const {
|
||||
return escaped_;
|
||||
}
|
||||
|
||||
@ -1243,19 +1246,19 @@ private:
|
||||
// matching
|
||||
////////////////
|
||||
|
||||
bool match(const char* const curr, char delim) {
|
||||
[[nodiscard]] bool match(const char* const curr, char delim) {
|
||||
return *curr == delim;
|
||||
};
|
||||
|
||||
bool match(const char* const curr, const std::string& delim) {
|
||||
[[nodiscard]] bool match(const char* const curr, const std::string& delim) {
|
||||
return std::strncmp(curr, delim.c_str(), delim.size()) == 0;
|
||||
};
|
||||
|
||||
size_t delimiter_size(char) {
|
||||
[[nodiscard]] size_t delimiter_size(char) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t delimiter_size(const std::string& delim) {
|
||||
[[nodiscard]] size_t delimiter_size(const std::string& delim) {
|
||||
return delim.size();
|
||||
}
|
||||
|
||||
@ -1276,7 +1279,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename Delim>
|
||||
std::tuple<size_t, bool> match_delimiter(line_ptr_type begin,
|
||||
[[nodiscard]] std::tuple<size_t, bool> match_delimiter(line_ptr_type begin,
|
||||
const Delim& delim) {
|
||||
line_ptr_type end = begin;
|
||||
|
||||
@ -1545,8 +1548,8 @@ namespace ss {
|
||||
#ifndef SSP_DISABLE_FAST_FLOAT
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>>
|
||||
to_num(const char* const begin, const char* const end) {
|
||||
T ret;
|
||||
auto [ptr, ec] = fast_float::from_chars(begin, end, ret);
|
||||
|
||||
@ -1559,8 +1562,8 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
#else
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>>
|
||||
to_num(const char* const begin, const char* const end) {
|
||||
static_assert(!std::is_same_v<T, long double>,
|
||||
"Conversion to long double is disabled");
|
||||
|
||||
@ -1633,7 +1636,7 @@ using int8 = numeric_wrapper<int8_t>;
|
||||
using uint8 = numeric_wrapper<uint8_t>;
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_integral_v<T>, std::optional<T>> to_num(
|
||||
[[nodiscard]] std::enable_if_t<std::is_integral_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
T ret;
|
||||
auto [ptr, ec] = std::from_chars(begin, end, ret);
|
||||
@ -1645,8 +1648,9 @@ std::enable_if_t<std::is_integral_v<T>, std::optional<T>> to_num(
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<is_instance_of_v<numeric_wrapper, T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
[[nodiscard]] std::enable_if_t<is_instance_of_v<numeric_wrapper, T>,
|
||||
std::optional<T>>
|
||||
to_num(const char* const begin, const char* const end) {
|
||||
T ret;
|
||||
auto [ptr, ec] = std::from_chars(begin, end, ret.value);
|
||||
|
||||
@ -1668,7 +1672,8 @@ struct unsupported_type {
|
||||
} /* namespace errors */
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<!std::is_integral_v<T> && !std::is_floating_point_v<T> &&
|
||||
[[nodiscard]] std::enable_if_t<!std::is_integral_v<T> &&
|
||||
!std::is_floating_point_v<T> &&
|
||||
!is_instance_of_v<std::optional, T> &&
|
||||
!is_instance_of_v<std::variant, T> &&
|
||||
!is_instance_of_v<numeric_wrapper, T>,
|
||||
@ -1680,7 +1685,8 @@ extract(const char*, const char*, T&) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_integral_v<T> || std::is_floating_point_v<T> ||
|
||||
[[nodiscard]] std::enable_if_t<std::is_integral_v<T> ||
|
||||
std::is_floating_point_v<T> ||
|
||||
is_instance_of_v<numeric_wrapper, T>,
|
||||
bool>
|
||||
extract(const char* begin, const char* end, T& value) {
|
||||
@ -1693,8 +1699,8 @@ extract(const char* begin, const char* end, T& value) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<is_instance_of_v<std::optional, T>, bool> extract(
|
||||
const char* begin, const char* end, T& value) {
|
||||
[[nodiscard]] std::enable_if_t<is_instance_of_v<std::optional, T>, bool>
|
||||
extract(const char* begin, const char* end, T& value) {
|
||||
typename T::value_type raw_value;
|
||||
if (extract(begin, end, raw_value)) {
|
||||
value = raw_value;
|
||||
@ -1705,7 +1711,8 @@ std::enable_if_t<is_instance_of_v<std::optional, T>, bool> extract(
|
||||
}
|
||||
|
||||
template <typename T, size_t I>
|
||||
bool extract_variant(const char* begin, const char* end, T& value) {
|
||||
[[nodiscard]] bool extract_variant(const char* begin, const char* end,
|
||||
T& value) {
|
||||
using IthType = std::variant_alternative_t<I, std::decay_t<T>>;
|
||||
IthType ithValue;
|
||||
if (extract<IthType>(begin, end, ithValue)) {
|
||||
@ -1718,7 +1725,7 @@ bool extract_variant(const char* begin, const char* end, T& value) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<is_instance_of_v<std::variant, T>, bool> extract(
|
||||
[[nodiscard]] std::enable_if_t<is_instance_of_v<std::variant, T>, bool> extract(
|
||||
const char* begin, const char* end, T& value) {
|
||||
return extract_variant<T, 0>(begin, end, value);
|
||||
}
|
||||
@ -1728,7 +1735,8 @@ std::enable_if_t<is_instance_of_v<std::variant, T>, bool> extract(
|
||||
////////////////
|
||||
|
||||
template <>
|
||||
inline bool extract(const char* begin, const char* end, bool& value) {
|
||||
[[nodiscard]] inline bool extract(const char* begin, const char* end,
|
||||
bool& value) {
|
||||
if (end == begin + 1) {
|
||||
if (*begin == '1') {
|
||||
value = true;
|
||||
@ -1755,19 +1763,21 @@ inline bool extract(const char* begin, const char* end, bool& value) {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool extract(const char* begin, const char* end, char& value) {
|
||||
[[nodiscard]] inline bool extract(const char* begin, const char* end,
|
||||
char& value) {
|
||||
value = *begin;
|
||||
return (end == begin + 1);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool extract(const char* begin, const char* end, std::string& value) {
|
||||
[[nodiscard]] inline bool extract(const char* begin, const char* end,
|
||||
std::string& value) {
|
||||
value = std::string{begin, end};
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool extract(const char* begin, const char* end,
|
||||
[[nodiscard]] inline bool extract(const char* begin, const char* end,
|
||||
std::string_view& value) {
|
||||
value = std::string_view{begin, static_cast<size_t>(end - begin)};
|
||||
return true;
|
||||
@ -1876,15 +1886,15 @@ public:
|
||||
// parses line with given delimiter, returns a 'T' object created with
|
||||
// extracted values of type 'Ts'
|
||||
template <typename T, typename... Ts>
|
||||
T convert_object(line_ptr_type line,
|
||||
const std::string& delim = default_delimiter) {
|
||||
[[nodiscard]] T convert_object(
|
||||
line_ptr_type line, const std::string& delim = default_delimiter) {
|
||||
return to_object<T>(convert<Ts...>(line, delim));
|
||||
}
|
||||
|
||||
// parses line with given delimiter, returns tuple of objects with
|
||||
// extracted values of type 'Ts'
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<Ts...> convert(
|
||||
[[nodiscard]] no_void_validator_tup_t<Ts...> convert(
|
||||
line_ptr_type line, const std::string& delim = default_delimiter) {
|
||||
split(line, delim);
|
||||
if (splitter_.valid()) {
|
||||
@ -1897,13 +1907,13 @@ public:
|
||||
|
||||
// parses already split line, returns 'T' object with extracted values
|
||||
template <typename T, typename... Ts>
|
||||
T convert_object(const split_data& elems) {
|
||||
[[nodiscard]] T convert_object(const split_data& elems) {
|
||||
return to_object<T>(convert<Ts...>(elems));
|
||||
}
|
||||
|
||||
// same as above, but uses cached split line
|
||||
template <typename T, typename... Ts>
|
||||
T convert_object() {
|
||||
[[nodiscard]] T convert_object() {
|
||||
return to_object<T>(convert<Ts...>());
|
||||
}
|
||||
|
||||
@ -1912,7 +1922,8 @@ public:
|
||||
// one argument is given which is a class which has a tied
|
||||
// method which returns a tuple, returns that type
|
||||
template <typename T, typename... Ts>
|
||||
no_void_validator_tup_t<T, Ts...> convert(const split_data& elems) {
|
||||
[[nodiscard]] no_void_validator_tup_t<T, Ts...> convert(
|
||||
const split_data& elems) {
|
||||
if constexpr (sizeof...(Ts) == 0 && is_instance_of_v<std::tuple, T>) {
|
||||
return convert_impl(elems, static_cast<T*>(nullptr));
|
||||
} else if constexpr (tied_class_v<T, Ts...>) {
|
||||
@ -1928,11 +1939,11 @@ public:
|
||||
|
||||
// same as above, but uses cached split line
|
||||
template <typename T, typename... Ts>
|
||||
no_void_validator_tup_t<T, Ts...> convert() {
|
||||
[[nodiscard]] no_void_validator_tup_t<T, Ts...> convert() {
|
||||
return convert<T, Ts...>(splitter_.split_data_);
|
||||
}
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
if constexpr (string_error) {
|
||||
return error_.empty();
|
||||
} else if constexpr (throw_on_error) {
|
||||
@ -1942,12 +1953,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& error_msg() const {
|
||||
[[nodiscard]] const std::string& error_msg() const {
|
||||
assert_string_error_defined<string_error>();
|
||||
return error_;
|
||||
}
|
||||
|
||||
bool unterminated_quote() const {
|
||||
[[nodiscard]] bool unterminated_quote() const {
|
||||
return splitter_.unterminated_quote();
|
||||
}
|
||||
|
||||
@ -1973,7 +1984,7 @@ private:
|
||||
return splitter_.resplit(new_line, new_size, delim);
|
||||
}
|
||||
|
||||
size_t size_shifted() {
|
||||
[[nodiscard]] size_t size_shifted() {
|
||||
return splitter_.size_shifted();
|
||||
}
|
||||
|
||||
@ -1989,7 +2000,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
std::string error_sufix(const string_range msg, size_t pos) const {
|
||||
[[nodiscard]] std::string error_sufix(const string_range msg,
|
||||
size_t pos) const {
|
||||
constexpr static auto reserve_size = 32;
|
||||
std::string error;
|
||||
error.reserve(reserve_size);
|
||||
@ -2117,7 +2129,8 @@ private:
|
||||
////////////////
|
||||
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<Ts...> convert_impl(const split_data& elems) {
|
||||
[[nodiscard]] no_void_validator_tup_t<Ts...> convert_impl(
|
||||
const split_data& elems) {
|
||||
clear_error();
|
||||
|
||||
if (!splitter_.valid()) {
|
||||
@ -2148,7 +2161,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||
[[nodiscard]] no_void_validator_tup_t<std::tuple<Ts...>> convert_impl(
|
||||
const split_data& elems, const std::tuple<Ts...>*) {
|
||||
return convert_impl<Ts...>(elems);
|
||||
}
|
||||
@ -2157,11 +2170,11 @@ private:
|
||||
// column mapping
|
||||
////////////////
|
||||
|
||||
bool columns_mapped() const {
|
||||
[[nodiscard]] bool columns_mapped() const {
|
||||
return !column_mappings_.empty();
|
||||
}
|
||||
|
||||
size_t column_position(size_t tuple_position) const {
|
||||
[[nodiscard]] size_t column_position(size_t tuple_position) const {
|
||||
if (!columns_mapped()) {
|
||||
return tuple_position;
|
||||
}
|
||||
@ -2192,7 +2205,7 @@ private:
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<T, std::string>) {
|
||||
extract(msg.first, msg.second, dst);
|
||||
static_cast<void>(extract(msg.first, msg.second, dst));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2238,7 +2251,8 @@ private:
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<Ts...> extract_tuple(const split_data& elems) {
|
||||
[[nodiscard]] no_void_validator_tup_t<Ts...> extract_tuple(
|
||||
const split_data& elems) {
|
||||
static_assert(!all_of_v<std::is_void, Ts...>,
|
||||
"at least one parameter must be non void");
|
||||
no_void_validator_tup_t<Ts...> ret{};
|
||||
@ -2327,7 +2341,7 @@ public:
|
||||
parser(const parser& other) = delete;
|
||||
parser& operator=(const parser& other) = delete;
|
||||
|
||||
bool valid() const {
|
||||
[[nodiscard]] bool valid() const {
|
||||
if constexpr (string_error) {
|
||||
return error_.empty();
|
||||
} else if constexpr (throw_on_error) {
|
||||
@ -2337,12 +2351,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& error_msg() const {
|
||||
[[nodiscard]] const std::string& error_msg() const {
|
||||
assert_string_error_defined<string_error>();
|
||||
return error_;
|
||||
}
|
||||
|
||||
bool eof() const {
|
||||
[[nodiscard]] bool eof() const {
|
||||
return eof_;
|
||||
}
|
||||
|
||||
@ -2351,21 +2365,21 @@ public:
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
T get_object() {
|
||||
[[nodiscard]] T get_object() {
|
||||
return to_object<T>(get_next<Ts...>());
|
||||
}
|
||||
|
||||
size_t line() const {
|
||||
[[nodiscard]] size_t line() const {
|
||||
return reader_.line_number_ > 0 ? reader_.line_number_ - 1
|
||||
: reader_.line_number_;
|
||||
}
|
||||
|
||||
size_t position() const {
|
||||
[[nodiscard]] size_t position() const {
|
||||
return reader_.chars_read_;
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
no_void_validator_tup_t<T, Ts...> get_next() {
|
||||
[[nodiscard]] no_void_validator_tup_t<T, Ts...> get_next() {
|
||||
std::optional<std::string> error;
|
||||
|
||||
if (!eof_) {
|
||||
@ -2416,12 +2430,12 @@ public:
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string raw_header() const {
|
||||
[[nodiscard]] std::string raw_header() const {
|
||||
assert_ignore_header_not_defined();
|
||||
return raw_header_;
|
||||
}
|
||||
|
||||
std::vector<std::string> header() {
|
||||
[[nodiscard]] std::vector<std::string> header() {
|
||||
assert_ignore_header_not_defined();
|
||||
clear_error();
|
||||
|
||||
@ -2440,7 +2454,7 @@ public:
|
||||
return split_header;
|
||||
}
|
||||
|
||||
bool field_exists(const std::string& field) {
|
||||
[[nodiscard]] bool field_exists(const std::string& field) {
|
||||
assert_ignore_header_not_defined();
|
||||
clear_error();
|
||||
|
||||
@ -2525,11 +2539,11 @@ public:
|
||||
iterator& operator=(const iterator& other) = delete;
|
||||
iterator& operator=(iterator&& other) = delete;
|
||||
|
||||
value& operator*() {
|
||||
[[nodiscard]] value& operator*() {
|
||||
return value_;
|
||||
}
|
||||
|
||||
value* operator->() {
|
||||
[[nodiscard]] value* operator->() {
|
||||
return &value_;
|
||||
}
|
||||
|
||||
@ -2554,13 +2568,15 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
friend bool operator==(const iterator& lhs, const iterator& rhs) {
|
||||
[[nodiscard]] friend bool operator==(const iterator& lhs,
|
||||
const iterator& rhs) {
|
||||
return (lhs.parser_ == nullptr && rhs.parser_ == nullptr) ||
|
||||
(lhs.parser_ == rhs.parser_ &&
|
||||
&lhs.value_ == &rhs.value_);
|
||||
}
|
||||
|
||||
friend bool operator!=(const iterator& lhs, const iterator& rhs) {
|
||||
[[nodiscard]] friend bool operator!=(const iterator& lhs,
|
||||
const iterator& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
@ -2572,11 +2588,11 @@ public:
|
||||
iterable(parser<Options...>* parser) : parser_{parser} {
|
||||
}
|
||||
|
||||
iterator begin() {
|
||||
[[nodiscard]] iterator begin() {
|
||||
return ++iterator{parser_};
|
||||
}
|
||||
|
||||
iterator end() {
|
||||
[[nodiscard]] iterator end() {
|
||||
return iterator{};
|
||||
}
|
||||
|
||||
@ -2585,12 +2601,12 @@ public:
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
auto iterate() {
|
||||
[[nodiscard]] auto iterate() {
|
||||
return iterable<false, Ts...>{this};
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
auto iterate_object() {
|
||||
[[nodiscard]] auto iterate_object() {
|
||||
return iterable<true, Ts...>{this};
|
||||
}
|
||||
|
||||
@ -2628,7 +2644,7 @@ public:
|
||||
return composite_with(std::move(value));
|
||||
}
|
||||
|
||||
std::tuple<Ts...> values() {
|
||||
[[nodiscard]] std::tuple<Ts...> values() {
|
||||
return values_;
|
||||
}
|
||||
|
||||
@ -2651,7 +2667,7 @@ public:
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
composite<Ts..., T> composite_with(T&& new_value) {
|
||||
[[nodiscard]] composite<Ts..., T> composite_with(T&& new_value) {
|
||||
auto merged_values =
|
||||
std::tuple_cat(std::move(values_),
|
||||
std::tuple<T>{parser_.valid()
|
||||
@ -2681,7 +2697,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename U, typename... Us>
|
||||
no_void_validator_tup_t<U, Us...> try_same() {
|
||||
[[nodiscard]] no_void_validator_tup_t<U, Us...> try_same() {
|
||||
parser_.clear_error();
|
||||
auto value =
|
||||
parser_.reader_.converter_.template convert<U, Us...>();
|
||||
@ -2702,8 +2718,8 @@ public:
|
||||
// tries to convert a line and returns a composite which is
|
||||
// able to try additional conversions in case of failure
|
||||
template <typename... Ts, typename Fun = none>
|
||||
composite<std::optional<no_void_validator_tup_t<Ts...>>> try_next(
|
||||
Fun&& fun = none{}) {
|
||||
[[nodiscard]] composite<std::optional<no_void_validator_tup_t<Ts...>>>
|
||||
try_next(Fun&& fun = none{}) {
|
||||
assert_throw_on_error_not_defined<throw_on_error>();
|
||||
using Ret = no_void_validator_tup_t<Ts...>;
|
||||
return try_invoke_and_make_composite<
|
||||
@ -2713,7 +2729,7 @@ public:
|
||||
// identical to try_next but returns composite with object instead of a
|
||||
// tuple
|
||||
template <typename T, typename... Ts, typename Fun = none>
|
||||
composite<std::optional<T>> try_object(Fun&& fun = none{}) {
|
||||
[[nodiscard]] composite<std::optional<T>> try_object(Fun&& fun = none{}) {
|
||||
assert_throw_on_error_not_defined<throw_on_error>();
|
||||
return try_invoke_and_make_composite<
|
||||
std::optional<T>>(get_object<T, Ts...>(), std::forward<Fun>(fun));
|
||||
@ -2764,7 +2780,8 @@ private:
|
||||
}
|
||||
|
||||
template <typename T, typename Fun = none>
|
||||
composite<T> try_invoke_and_make_composite(T&& value, Fun&& fun) {
|
||||
[[nodiscard]] composite<T> try_invoke_and_make_composite(T&& value,
|
||||
Fun&& fun) {
|
||||
if (valid()) {
|
||||
try_invoke(*value, std::forward<Fun>(fun));
|
||||
}
|
||||
@ -2780,7 +2797,8 @@ private:
|
||||
"cannot use this method when 'ignore_header' is defined");
|
||||
}
|
||||
|
||||
bool strict_split(header_splitter& splitter, std::string& header) {
|
||||
[[nodiscard]] bool strict_split(header_splitter& splitter,
|
||||
std::string& header) {
|
||||
if (header.empty()) {
|
||||
return false;
|
||||
}
|
||||
@ -2827,7 +2845,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<size_t> header_index(const std::string& field) {
|
||||
[[nodiscard]] std::optional<size_t> header_index(const std::string& field) {
|
||||
auto it = std::find(header_.begin(), header_.end(), field);
|
||||
|
||||
if (it == header_.end()) {
|
||||
@ -3098,7 +3116,7 @@ private:
|
||||
reader& operator=(const reader& other) = delete;
|
||||
|
||||
// read next line each time in order to set eof_
|
||||
bool read_next() {
|
||||
[[nodiscard]] bool read_next() {
|
||||
next_line_converter_.clear_error();
|
||||
size_t size = 0;
|
||||
while (size == 0) {
|
||||
@ -3190,7 +3208,7 @@ private:
|
||||
std::swap(converter_, next_line_converter_);
|
||||
}
|
||||
|
||||
bool multiline_limit_reached(size_t& limit) {
|
||||
[[nodiscard]] bool multiline_limit_reached(size_t& limit) {
|
||||
if constexpr (multiline::size > 0) {
|
||||
if (limit++ >= multiline::size) {
|
||||
next_line_converter_.handle_error_multiline_limit_reached();
|
||||
@ -3200,7 +3218,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool escaped_eol(size_t size) {
|
||||
[[nodiscard]] bool escaped_eol(size_t size) {
|
||||
const char* curr = nullptr;
|
||||
for (curr = next_line_buffer_ + size - 1;
|
||||
curr >= next_line_buffer_ &&
|
||||
@ -3210,7 +3228,7 @@ private:
|
||||
return (next_line_buffer_ - curr + size) % 2 == 0;
|
||||
}
|
||||
|
||||
bool unterminated_quote() {
|
||||
[[nodiscard]] bool unterminated_quote() {
|
||||
return next_line_converter_.unterminated_quote();
|
||||
}
|
||||
|
||||
@ -3225,7 +3243,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
size_t remove_eol(char*& buffer, size_t ssize) {
|
||||
[[nodiscard]] size_t remove_eol(char*& buffer, size_t ssize) {
|
||||
if (buffer[ssize - 1] != '\n') {
|
||||
crlf_ = false;
|
||||
return ssize;
|
||||
@ -3255,7 +3273,8 @@ private:
|
||||
first_size += second_size;
|
||||
}
|
||||
|
||||
bool append_next_line_to_buffer(char*& buffer, size_t& line_size,
|
||||
[[nodiscard]] bool append_next_line_to_buffer(char*& buffer,
|
||||
size_t& line_size,
|
||||
size_t buffer_size) {
|
||||
undo_remove_eol(buffer, line_size, buffer_size);
|
||||
|
||||
@ -3275,7 +3294,7 @@ private:
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string get_buffer() {
|
||||
[[nodiscard]] std::string get_buffer() {
|
||||
return std::string{next_line_buffer_, next_line_size_};
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "test_helpers.hpp"
|
||||
#include <algorithm>
|
||||
#include <ss/converter.hpp>
|
||||
|
||||
TEST_CASE("converter test split") {
|
||||
@ -11,7 +10,8 @@ TEST_CASE("converter test split") {
|
||||
{" x x x x | x ", {" x x x x ", " x "}, "|"},
|
||||
{"a::b::c::d", {"a", "b", "c", "d"}, "::"},
|
||||
{"x\t-\ty", {"x", "y"}, "\t-\t"},
|
||||
{"x", {"x"}, ","}} // clang-format on
|
||||
{"x", {"x"}, ","}}
|
||||
// clang-format on
|
||||
) {
|
||||
auto split = c.split(s, delim);
|
||||
CHECK_EQ(split.size(), expected.size());
|
||||
@ -278,36 +278,37 @@ TEST_CASE_TEMPLATE("converter test valid conversions with exceptions", T, int,
|
||||
TEST_CASE_TEMPLATE("converter test invalid conversions", T, int, ss::uint8) {
|
||||
ss::converter c;
|
||||
|
||||
c.convert<T>("");
|
||||
std::ignore = c.convert<T>("");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<T>("1", "");
|
||||
std::ignore = c.convert<T>("1", "");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<T>("10", "");
|
||||
std::ignore = c.convert<T>("10", "");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<T, void>("");
|
||||
std::ignore = c.convert<T, void>("");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<T, void>(",junk");
|
||||
std::ignore = c.convert<T, void>(",junk");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<void, T>("junk,");
|
||||
std::ignore = c.convert<void, T>("junk,");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<T>("x");
|
||||
std::ignore = c.convert<T>("x");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<T, void>("x");
|
||||
std::ignore = c.convert<T, void>("x");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<T, void>("x,junk");
|
||||
std::ignore = c.convert<T, void>("x,junk");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<void, T>("junk,x");
|
||||
std::ignore = c.convert<void, T>("junk,x");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
std::ignore =
|
||||
c.convert<void, std::variant<T, double>, double>("junk;.5.5;6", ";");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
}
|
||||
@ -316,34 +317,36 @@ TEST_CASE_TEMPLATE("converter test invalid conversions with exceptions", T, int,
|
||||
ss::uint8) {
|
||||
ss::converter<ss::throw_on_error> c;
|
||||
|
||||
REQUIRE_EXCEPTION(c.convert<T>(""));
|
||||
REQUIRE_EXCEPTION(c.convert<T>("1", ""));
|
||||
REQUIRE_EXCEPTION(c.convert<T>("10", ""));
|
||||
REQUIRE_EXCEPTION(c.convert<T, void>(""));
|
||||
REQUIRE_EXCEPTION(c.convert<T, void>(",junk"));
|
||||
REQUIRE_EXCEPTION(c.convert<void, T>("junk,"));
|
||||
REQUIRE_EXCEPTION(c.convert<T>("x"));
|
||||
REQUIRE_EXCEPTION(c.convert<T, void>("x"));
|
||||
REQUIRE_EXCEPTION(c.convert<T, void>("x,junk"));
|
||||
REQUIRE_EXCEPTION(c.convert<void, T>("junk,x"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<T>(""));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<T>("1", ""));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<T>("10", ""));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<T, void>(""));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<T, void>(",junk"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<void, T>("junk,"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<T>("x"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<T, void>("x"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<T, void>("x,junk"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<void, T>("junk,x"));
|
||||
REQUIRE_EXCEPTION(
|
||||
c.convert<void, std::variant<T, double>, double>("junk;.5.5;6", ";"));
|
||||
std::ignore =
|
||||
c.convert<void, std::variant<T, double>, double>("junk;.5.5;6",
|
||||
";"));
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("converter test ss:ax restriction (all except)", T, int,
|
||||
ss::uint8) {
|
||||
ss::converter c;
|
||||
|
||||
c.convert<ss::ax<T, 0>>("0");
|
||||
std::ignore = c.convert<ss::ax<T, 0>>("0");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::ax<T, 0, 1, 2>>("1");
|
||||
std::ignore = c.convert<ss::ax<T, 0, 1, 2>>("1");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<void, char, ss::ax<T, 0, 1, 2>>("junk,c,1");
|
||||
std::ignore = c.convert<void, char, ss::ax<T, 0, 1, 2>>("junk,c,1");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::ax<T, 1>, char>("1,c");
|
||||
std::ignore = c.convert<ss::ax<T, 1>, char>("1,c");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
{
|
||||
T tup = c.convert<ss::ax<T, 1>>("3");
|
||||
@ -367,10 +370,11 @@ TEST_CASE_TEMPLATE(
|
||||
ss::uint8) {
|
||||
ss::converter<ss::throw_on_error> c;
|
||||
|
||||
REQUIRE_EXCEPTION(c.convert<ss::ax<T, 0>>("0"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::ax<T, 0, 1, 2>>("1"));
|
||||
REQUIRE_EXCEPTION(c.convert<void, char, ss::ax<T, 0, 1, 2>>("junk,c,1"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::ax<T, 1>, char>("1,c"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::ax<T, 0>>("0"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::ax<T, 0, 1, 2>>("1"));
|
||||
REQUIRE_EXCEPTION(
|
||||
std::ignore = c.convert<void, char, ss::ax<T, 0, 1, 2>>("junk,c,1"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::ax<T, 1>, char>("1,c"));
|
||||
|
||||
try {
|
||||
{
|
||||
@ -393,13 +397,13 @@ TEST_CASE_TEMPLATE(
|
||||
TEST_CASE("converter test ss:nx restriction (none except)") {
|
||||
ss::converter c;
|
||||
|
||||
c.convert<ss::nx<int, 1>>("3");
|
||||
std::ignore = c.convert<ss::nx<int, 1>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<char, ss::nx<int, 1, 2, 69>>("c,3");
|
||||
std::ignore = c.convert<char, ss::nx<int, 1, 2, 69>>("c,3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::nx<int, 1>, char>("3,c");
|
||||
std::ignore = c.convert<ss::nx<int, 1>, char>("3,c");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
{
|
||||
@ -427,9 +431,10 @@ TEST_CASE("converter test ss:nx restriction (none except)") {
|
||||
TEST_CASE("converter test ss:nx restriction (none except) with exceptions") {
|
||||
ss::converter<ss::throw_on_error> c;
|
||||
|
||||
REQUIRE_EXCEPTION(c.convert<ss::nx<int, 1>>("3"));
|
||||
REQUIRE_EXCEPTION(c.convert<char, ss::nx<int, 1, 2, 69>>("c,3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::nx<int, 1>, char>("3,c"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::nx<int, 1>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore =
|
||||
c.convert<char, ss::nx<int, 1, 2, 69>>("c,3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::nx<int, 1>, char>("3,c"));
|
||||
|
||||
try {
|
||||
{
|
||||
@ -461,13 +466,13 @@ TEST_CASE_TEMPLATE("converter test ss:ir restriction (in range)", T, int,
|
||||
ss::uint8) {
|
||||
ss::converter c;
|
||||
|
||||
c.convert<ss::ir<T, 0, 2>>("3");
|
||||
std::ignore = c.convert<ss::ir<T, 0, 2>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<char, ss::ir<T, 4, 69>>("c,3");
|
||||
std::ignore = c.convert<char, ss::ir<T, 4, 69>>("c,3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::ir<T, 1, 2>, char>("3,c");
|
||||
std::ignore = c.convert<ss::ir<T, 1, 2>, char>("3,c");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
{
|
||||
@ -497,9 +502,9 @@ TEST_CASE_TEMPLATE(
|
||||
ss::uint8) {
|
||||
ss::converter<ss::throw_on_error> c;
|
||||
|
||||
REQUIRE_EXCEPTION(c.convert<ss::ir<T, 0, 2>>("3"));
|
||||
REQUIRE_EXCEPTION(c.convert<char, ss::ir<T, 4, 69>>("c,3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::ir<T, 1, 2>, char>("3,c"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::ir<T, 0, 2>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<char, ss::ir<T, 4, 69>>("c,3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::ir<T, 1, 2>, char>("3,c"));
|
||||
|
||||
try {
|
||||
{
|
||||
@ -530,16 +535,16 @@ TEST_CASE_TEMPLATE(
|
||||
TEST_CASE("converter test ss:oor restriction (out of range)") {
|
||||
ss::converter c;
|
||||
|
||||
c.convert<ss::oor<int, 1, 5>>("3");
|
||||
std::ignore = c.convert<ss::oor<int, 1, 5>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::oor<int, 0, 2>>("2");
|
||||
std::ignore = c.convert<ss::oor<int, 0, 2>>("2");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<char, ss::oor<int, 0, 1>, void>("c,1,junk");
|
||||
std::ignore = c.convert<char, ss::oor<int, 0, 1>, void>("c,1,junk");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::oor<int, 1, 20>, char>("1,c");
|
||||
std::ignore = c.convert<ss::oor<int, 1, 20>, char>("1,c");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
{
|
||||
@ -564,10 +569,12 @@ TEST_CASE("converter test ss:oor restriction (out of range)") {
|
||||
TEST_CASE("converter test ss:oor restriction (out of range) with exceptions") {
|
||||
ss::converter<ss::throw_on_error> c;
|
||||
|
||||
REQUIRE_EXCEPTION(c.convert<ss::oor<int, 1, 5>>("3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::oor<int, 0, 2>>("2"));
|
||||
REQUIRE_EXCEPTION(c.convert<char, ss::oor<int, 0, 1>, void>("c,1,junk"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::oor<int, 1, 20>, char>("1,c"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::oor<int, 1, 5>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::oor<int, 0, 2>>("2"));
|
||||
REQUIRE_EXCEPTION(
|
||||
std::ignore = c.convert<char, ss::oor<int, 0, 1>, void>("c,1,junk"));
|
||||
REQUIRE_EXCEPTION(std::ignore =
|
||||
c.convert<ss::oor<int, 1, 20>, char>("1,c"));
|
||||
|
||||
try {
|
||||
{
|
||||
@ -608,19 +615,19 @@ inline bool ss::extract(const char* begin, const char* end,
|
||||
TEST_CASE("converter test ss:ne restriction (not empty)") {
|
||||
ss::converter c;
|
||||
|
||||
c.convert<ss::ne<std::string>>("");
|
||||
std::ignore = c.convert<ss::ne<std::string>>("");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<int, ss::ne<std::string>>("3,");
|
||||
std::ignore = c.convert<int, ss::ne<std::string>>("3,");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::ne<std::string>, int>(",3");
|
||||
std::ignore = c.convert<ss::ne<std::string>, int>(",3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<void, ss::ne<std::string>, int>("junk,,3");
|
||||
std::ignore = c.convert<void, ss::ne<std::string>, int>("junk,,3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::ne<std::vector<int>>>("");
|
||||
std::ignore = c.convert<ss::ne<std::vector<int>>>("");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
{
|
||||
@ -643,11 +650,12 @@ TEST_CASE("converter test ss:ne restriction (not empty)") {
|
||||
TEST_CASE("converter test ss:ne restriction (not empty) with exceptions") {
|
||||
ss::converter<ss::throw_on_error> c;
|
||||
|
||||
REQUIRE_EXCEPTION(c.convert<ss::ne<std::string>>(""));
|
||||
REQUIRE_EXCEPTION(c.convert<int, ss::ne<std::string>>("3,"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::ne<std::string>, int>(",3"));
|
||||
REQUIRE_EXCEPTION(c.convert<void, ss::ne<std::string>, int>("junk,,3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::ne<std::vector<int>>>(""));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::ne<std::string>>(""));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<int, ss::ne<std::string>>("3,"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::ne<std::string>, int>(",3"));
|
||||
REQUIRE_EXCEPTION(std::ignore =
|
||||
c.convert<void, ss::ne<std::string>, int>("junk,,3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::ne<std::vector<int>>>(""));
|
||||
|
||||
try {
|
||||
{
|
||||
@ -675,22 +683,22 @@ TEST_CASE(
|
||||
"converter test ss:lt ss::lte ss::gt ss::gte restriction (in range)") {
|
||||
ss::converter c;
|
||||
|
||||
c.convert<ss::lt<int, 3>>("3");
|
||||
std::ignore = c.convert<ss::lt<int, 3>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::lt<int, 2>>("3");
|
||||
std::ignore = c.convert<ss::lt<int, 2>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::gt<int, 3>>("3");
|
||||
std::ignore = c.convert<ss::gt<int, 3>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::gt<int, 4>>("3");
|
||||
std::ignore = c.convert<ss::gt<int, 4>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::lte<int, 2>>("3");
|
||||
std::ignore = c.convert<ss::lte<int, 2>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
c.convert<ss::gte<int, 4>>("3");
|
||||
std::ignore = c.convert<ss::gte<int, 4>>("3");
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
{
|
||||
@ -734,12 +742,12 @@ TEST_CASE("converter test ss:lt ss::lte ss::gt ss::gte restriction (in range) "
|
||||
"with exception") {
|
||||
ss::converter<ss::throw_on_error> c;
|
||||
|
||||
REQUIRE_EXCEPTION(c.convert<ss::lt<int, 3>>("3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::lt<int, 2>>("3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::gt<int, 3>>("3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::gt<int, 4>>("3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::lte<int, 2>>("3"));
|
||||
REQUIRE_EXCEPTION(c.convert<ss::gte<int, 4>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::lt<int, 3>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::lt<int, 2>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::gt<int, 3>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::gt<int, 4>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::lte<int, 2>>("3"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<ss::gte<int, 4>>("3"));
|
||||
|
||||
try {
|
||||
{
|
||||
@ -784,14 +792,14 @@ TEST_CASE("converter test ss:lt ss::lte ss::gt ss::gte restriction (in range) "
|
||||
|
||||
TEST_CASE("converter test error mode") {
|
||||
ss::converter<ss::string_error> c;
|
||||
c.convert<int>("junk");
|
||||
std::ignore = c.convert<int>("junk");
|
||||
CHECK_FALSE(c.valid());
|
||||
CHECK_FALSE(c.error_msg().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("converter test throw on error mode") {
|
||||
ss::converter<ss::throw_on_error> c;
|
||||
REQUIRE_EXCEPTION(c.convert<int>("junk"));
|
||||
REQUIRE_EXCEPTION(std::ignore = c.convert<int>("junk"));
|
||||
}
|
||||
|
||||
TEST_CASE("converter test converter with quotes spacing and escaping") {
|
||||
@ -908,7 +916,7 @@ TEST_CASE("converter test invalid split conversions") {
|
||||
|
||||
{
|
||||
// mismatched quote
|
||||
c.convert<std::string, std::string, double, char>(
|
||||
std::ignore = c.convert<std::string, std::string, double, char>(
|
||||
buff(R"( "just , some , "12.3","a" )"));
|
||||
CHECK_FALSE(c.valid());
|
||||
CHECK_FALSE(c.unterminated_quote());
|
||||
@ -917,7 +925,7 @@ TEST_CASE("converter test invalid split conversions") {
|
||||
|
||||
{
|
||||
// unterminated quote
|
||||
c.convert<std::string, std::string, double, std::string>(
|
||||
std::ignore = c.convert<std::string, std::string, double, std::string>(
|
||||
buff(R"( ju\,st , "so,me" , 12.34 , "str""ings)"));
|
||||
CHECK_FALSE(c.valid());
|
||||
CHECK(c.unterminated_quote());
|
||||
@ -926,7 +934,7 @@ TEST_CASE("converter test invalid split conversions") {
|
||||
|
||||
{
|
||||
// unterminated escape
|
||||
c.convert<std::string, std::string, double, std::string>(
|
||||
std::ignore = c.convert<std::string, std::string, double, std::string>(
|
||||
buff(R"(just,some,2,strings\)"));
|
||||
CHECK_FALSE(c.valid());
|
||||
CHECK_FALSE(c.unterminated_quote());
|
||||
@ -935,7 +943,7 @@ TEST_CASE("converter test invalid split conversions") {
|
||||
|
||||
{
|
||||
// unterminated escape while quoting
|
||||
c.convert<std::string, std::string, double, std::string>(
|
||||
std::ignore = c.convert<std::string, std::string, double, std::string>(
|
||||
buff(R"(just,some,2,"strings\)"));
|
||||
CHECK_FALSE(c.valid());
|
||||
CHECK_FALSE(c.unterminated_quote());
|
||||
@ -944,7 +952,7 @@ TEST_CASE("converter test invalid split conversions") {
|
||||
|
||||
{
|
||||
// unterminated escaped quote
|
||||
c.convert<std::string, std::string, double, std::string>(
|
||||
std::ignore = c.convert<std::string, std::string, double, std::string>(
|
||||
buff(R"(just,some,2,"strings\")"));
|
||||
CHECK_FALSE(c.valid());
|
||||
CHECK(c.unterminated_quote());
|
||||
@ -958,27 +966,32 @@ TEST_CASE("converter test invalid split conversions with exceptions") {
|
||||
c;
|
||||
|
||||
// mismatched quote
|
||||
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, char>(
|
||||
REQUIRE_EXCEPTION(std::ignore =
|
||||
c.convert<std::string, std::string, double, char>(
|
||||
buff(R"( "just , some , "12.3","a" )")));
|
||||
CHECK_FALSE(c.unterminated_quote());
|
||||
|
||||
// unterminated quote
|
||||
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, std::string>(
|
||||
REQUIRE_EXCEPTION(
|
||||
std::ignore = c.convert<std::string, std::string, double, std::string>(
|
||||
buff(R"( ju\,st , "so,me" , 12.34 , "str""ings)")));
|
||||
CHECK(c.unterminated_quote());
|
||||
|
||||
// unterminated escape
|
||||
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, std::string>(
|
||||
REQUIRE_EXCEPTION(
|
||||
std::ignore = c.convert<std::string, std::string, double, std::string>(
|
||||
buff(R"(just,some,2,strings\)")));
|
||||
CHECK_FALSE(c.unterminated_quote());
|
||||
|
||||
// unterminated escape while quoting
|
||||
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, std::string>(
|
||||
REQUIRE_EXCEPTION(
|
||||
std::ignore = c.convert<std::string, std::string, double, std::string>(
|
||||
buff(R"(just,some,2,"strings\)")));
|
||||
CHECK_FALSE(c.unterminated_quote());
|
||||
|
||||
// unterminated escaped quote
|
||||
REQUIRE_EXCEPTION(c.convert<std::string, std::string, double, std::string>(
|
||||
REQUIRE_EXCEPTION(
|
||||
std::ignore = c.convert<std::string, std::string, double, std::string>(
|
||||
buff(R"(just,some,2,"strings\")")));
|
||||
CHECK(c.unterminated_quote());
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "test_helpers.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
#define SSP_DISABLE_FAST_FLOAT
|
||||
#include <ss/extract.hpp>
|
||||
|
@ -212,6 +212,7 @@ template <typename T>
|
||||
}
|
||||
};
|
||||
|
||||
// Evade small string optimization
|
||||
out.reserve(sizeof(out) + 1);
|
||||
|
||||
copy_if_whitespaces();
|
||||
|
@ -12,7 +12,8 @@
|
||||
#include <unordered_set>
|
||||
|
||||
namespace {
|
||||
[[maybe_unused]] void replace_all(std::string& s, const std::string& from,
|
||||
#ifdef _WIN32
|
||||
void replace_all(std::string& s, const std::string& from,
|
||||
const std::string& to) {
|
||||
if (from.empty()) return;
|
||||
size_t start_pos = 0;
|
||||
@ -21,6 +22,7 @@ namespace {
|
||||
start_pos += to.length();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename... Ts>
|
||||
void expect_error_on_command(ss::parser<Ts...>& p,
|
||||
@ -56,7 +58,7 @@ struct X {
|
||||
double d;
|
||||
std::string s;
|
||||
|
||||
std::string to_string() const {
|
||||
[[nodiscard]] std::string to_string() const {
|
||||
if (s == empty) {
|
||||
return "";
|
||||
}
|
||||
@ -67,14 +69,15 @@ struct X {
|
||||
.append(delim)
|
||||
.append(s);
|
||||
}
|
||||
auto tied() const {
|
||||
|
||||
[[nodiscard]] auto tied() const {
|
||||
return std::tie(i, d, s);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t<ss::has_m_tied_t<T>, bool> operator==(const T& lhs,
|
||||
const T& rhs) {
|
||||
[[nodiscard]] std::enable_if_t<ss::has_m_tied_t<T>, bool> operator==(
|
||||
const T& lhs, const T& rhs) {
|
||||
return lhs.tied() == rhs.tied();
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ struct Y {
|
||||
.append(s3);
|
||||
}
|
||||
|
||||
auto tied() const {
|
||||
[[nodiscard]] auto tied() const {
|
||||
return std::tie(s1, s2, s3);
|
||||
}
|
||||
};
|
||||
@ -115,7 +115,8 @@ TEST_CASE_TEMPLATE("test line method", T, ParserOptionCombinations) {
|
||||
CHECK_EQ(p.line(), expected_line);
|
||||
|
||||
while (!p.eof()) {
|
||||
auto _ = p.template get_next<std::string, std::string, std::string>();
|
||||
std::ignore =
|
||||
p.template get_next<std::string, std::string, std::string>();
|
||||
++expected_line;
|
||||
CHECK_EQ(p.line(), expected_line);
|
||||
}
|
||||
|
@ -51,12 +51,14 @@ TEST_CASE_TEMPLATE("test moving of parsed composite values", T,
|
||||
// to compile is enough
|
||||
return;
|
||||
auto [p, _] = make_parser<buffer_mode, ErrorMode>("", "");
|
||||
std::ignore =
|
||||
p.template try_next<my_string, my_string, my_string>()
|
||||
.template or_else<my_string, my_string, my_string, my_string>(
|
||||
[](auto&&) {})
|
||||
.template or_else<my_string>([](auto&) {})
|
||||
.template or_else<xyz>([](auto&&) {})
|
||||
.template or_object<xyz, my_string, my_string, my_string>([](auto&&) {})
|
||||
.template or_object<xyz, my_string, my_string, my_string>(
|
||||
[](auto&&) {})
|
||||
.template or_else<std::tuple<my_string, my_string, my_string>>(
|
||||
[](auto&, auto&, auto&) {});
|
||||
}
|
||||
@ -73,7 +75,7 @@ TEST_CASE_TEMPLATE("parser test string error mode", BufferMode, std::true_type,
|
||||
auto [p, _] = make_parser<BufferMode::value, ss::string_error>(f.name, ",");
|
||||
|
||||
REQUIRE_FALSE(p.eof());
|
||||
p.template get_next<int>();
|
||||
std::ignore = p.template get_next<int>();
|
||||
CHECK_FALSE(p.valid());
|
||||
CHECK_FALSE(p.error_msg().empty());
|
||||
}
|
||||
@ -92,7 +94,7 @@ TEST_CASE_TEMPLATE("parser throw on error mode", BufferMode, std::true_type,
|
||||
|
||||
REQUIRE_FALSE(p.eof());
|
||||
try {
|
||||
p.template get_next<int>();
|
||||
std::ignore = p.template get_next<int>();
|
||||
FAIL("Expected exception...");
|
||||
} catch (const std::exception& e) {
|
||||
CHECK_FALSE(std::string{e.what()}.empty());
|
||||
@ -148,6 +150,7 @@ TEST_CASE_TEMPLATE("test quote multiline", T, ParserOptionCombinations) {
|
||||
make_parser<buffer_mode, ErrorMode, ss::quote<'"'>>(f.name, ",");
|
||||
while (!p.eof()) {
|
||||
auto command = [&p_no_multiline = p_no_multiline] {
|
||||
std::ignore =
|
||||
p_no_multiline.template get_next<int, double, std::string>();
|
||||
};
|
||||
expect_error_on_command(p_no_multiline, command);
|
||||
|
@ -83,7 +83,7 @@ void test_unterminated_line(const std::vector<std::string>& lines,
|
||||
size_t line = 0;
|
||||
while (!p.eof()) {
|
||||
auto command = [&p = p] {
|
||||
p.template get_next<int, double, std::string>();
|
||||
std::ignore = p.template get_next<int, double, std::string>();
|
||||
};
|
||||
|
||||
if (line == bad_line) {
|
||||
|
@ -228,7 +228,7 @@ void test_invalid_fields(const std::vector<std::string>& lines,
|
||||
auto [p, _] = make_parser<buffer_mode, ErrorMode>(f.name, ",");
|
||||
auto command = [&p = p, &fields = fields] {
|
||||
p.use_fields(fields.at(0));
|
||||
p.template get_next<std::string, std::string>();
|
||||
std::ignore = p.template get_next<std::string, std::string>();
|
||||
};
|
||||
check_header(p);
|
||||
|
||||
@ -428,7 +428,7 @@ TEST_CASE_TEMPLATE("test invalid header", T, ParserOptionCombinations) {
|
||||
{
|
||||
auto [p, _] =
|
||||
make_parser<buffer_mode, ErrorMode, ss::quote<'"'>>(f.name);
|
||||
auto command = [&p = p] { p.header(); };
|
||||
auto command = [&p = p] { std::ignore = p.header(); };
|
||||
expect_error_on_command(p, command);
|
||||
CHECK_EQ(p.raw_header(), "\"Int");
|
||||
}
|
||||
@ -437,7 +437,7 @@ TEST_CASE_TEMPLATE("test invalid header", T, ParserOptionCombinations) {
|
||||
auto [p, _] =
|
||||
make_parser<buffer_mode, ErrorMode, ss::quote<'"'>, ss::multiline>(
|
||||
f.name);
|
||||
auto command = [&p = p] { p.header(); };
|
||||
auto command = [&p = p] { std::ignore = p.header(); };
|
||||
expect_error_on_command(p, command);
|
||||
CHECK_EQ(p.raw_header(), "\"Int");
|
||||
}
|
||||
@ -445,7 +445,7 @@ TEST_CASE_TEMPLATE("test invalid header", T, ParserOptionCombinations) {
|
||||
{
|
||||
auto [p, _] = make_parser<buffer_mode, ErrorMode, ss::quote<'"'>,
|
||||
ss::escape<'\\'>, ss::multiline>(f.name);
|
||||
auto command = [&p = p] { p.header(); };
|
||||
auto command = [&p = p] { std::ignore = p.header(); };
|
||||
expect_error_on_command(p, command);
|
||||
CHECK_EQ(p.raw_header(), "\"Int");
|
||||
}
|
||||
@ -460,7 +460,7 @@ TEST_CASE_TEMPLATE("test invalid header", T, ParserOptionCombinations) {
|
||||
{
|
||||
auto [p, _] =
|
||||
make_parser<buffer_mode, ErrorMode, ss::escape<'\\'>>(f.name);
|
||||
auto command = [&p = p] { p.header(); };
|
||||
auto command = [&p = p] { std::ignore = p.header(); };
|
||||
expect_error_on_command(p, command);
|
||||
CHECK_EQ(p.raw_header(), "Int\\");
|
||||
}
|
||||
@ -468,7 +468,7 @@ TEST_CASE_TEMPLATE("test invalid header", T, ParserOptionCombinations) {
|
||||
{
|
||||
auto [p, _] = make_parser<buffer_mode, ErrorMode, ss::escape<'\\'>,
|
||||
ss::multiline>(f.name);
|
||||
auto command = [&p = p] { p.header(); };
|
||||
auto command = [&p = p] { std::ignore = p.header(); };
|
||||
expect_error_on_command(p, command);
|
||||
CHECK_EQ(p.raw_header(), "Int\\");
|
||||
}
|
||||
@ -476,7 +476,7 @@ TEST_CASE_TEMPLATE("test invalid header", T, ParserOptionCombinations) {
|
||||
{
|
||||
auto [p, _] = make_parser<buffer_mode, ErrorMode, ss::escape<'\\'>,
|
||||
ss::quote<'"'>, ss::multiline>(f.name);
|
||||
auto command = [&p = p] { p.header(); };
|
||||
auto command = [&p = p] { std::ignore = p.header(); };
|
||||
expect_error_on_command(p, command);
|
||||
CHECK_EQ(p.raw_header(), "Int\\");
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ struct column {
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
column make_column(const std::string& input_header,
|
||||
[[nodiscard]] column make_column(const std::string& input_header,
|
||||
const std::vector<field>& input_fields) {
|
||||
using setup = ss::setup<Ts...>;
|
||||
std::vector<field> filtered_fields;
|
||||
@ -127,8 +127,8 @@ column make_column(const std::string& input_header,
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<std::string> generate_csv_data(const std::vector<field>& data,
|
||||
const std::string& delim) {
|
||||
[[nodiscard]] std::vector<std::string> generate_csv_data(
|
||||
const std::vector<field>& data, const std::string& delim) {
|
||||
(void)delim;
|
||||
using setup = ss::setup<Ts...>;
|
||||
constexpr static auto escape = '\\';
|
||||
|
@ -9,4 +9,3 @@ TEST_CASE("parser test various cases version 2 segment 1") {
|
||||
test_option_combinations3<escape>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -10,4 +10,3 @@ TEST_CASE("parser test various cases version 2 segment 2") {
|
||||
test_option_combinations3<escape, quote>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -11,4 +11,3 @@ TEST_CASE("parser test various cases version 2 segment 3") {
|
||||
test_option_combinations3<quote, multiline>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -12,4 +12,3 @@ TEST_CASE("parser test various cases version 2 segment 4") {
|
||||
test_option_combinations3<escape, quote, multiline_r>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -13,4 +13,3 @@ TEST_CASE("parser test various cases version 2 segment 5") {
|
||||
test_option_combinations<escape, quote, multiline, trimr>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -8,4 +8,3 @@ TEST_CASE("parser test various cases version 2 segment 6") {
|
||||
|
||||
test_option_combinations3<escape, quote, multiline>();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user