mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
304ca6ef0f | ||
| 103ff33f21 | |||
|
|
8b928de086 | ||
| 6edce88d79 | |||
|
|
6196f7796b | ||
| 5672aa635e | |||
| 3eefac93b1 | |||
| 774f452689 |
21
README.md
21
README.md
@@ -53,20 +53,20 @@ Brian S. Wolfe 40 1.9
|
|||||||
Bill (Heath) Gates 65 3.3
|
Bill (Heath) Gates 65 3.3
|
||||||
```
|
```
|
||||||
# Features
|
# Features
|
||||||
* [Works on any type](#Custom-conversions)
|
* [Works on any type](#custom-conversions)
|
||||||
* Easy to use
|
* Easy to use
|
||||||
* No exceptions
|
* No exceptions
|
||||||
* [Works with headers](#Headers)
|
* [Works with headers](#headers)
|
||||||
* [Works with quotes, escapes and spacings](#Setup)
|
* [Works with quotes, escapes and spacings](#setup)
|
||||||
* [Works with values containing new lines](#Multiline)
|
* [Works with values containing new lines](#multiline)
|
||||||
* [Columns and rows can be ignored](#Special-types)
|
* [Columns and rows can be ignored](#special-types)
|
||||||
* Works with any type of delimiter
|
* Works with any type of delimiter
|
||||||
* Can return whole objects composed of converted values
|
* Can return whole objects composed of converted values
|
||||||
* [Descriptive error handling can be enabled](#Error-handling)
|
* [Descriptive error handling can be enabled](#error-handling)
|
||||||
* [Restrictions can be added for each column](#Restrictions)
|
* [Restrictions can be added for each column](#restrictions)
|
||||||
* [Works with `std::optional` and `std::variant`](#Special-types)
|
* [Works with `std::optional` and `std::variant`](#special-types)
|
||||||
* Works with **`CRLF`** and **`LF`**
|
* Works with **`CRLF`** and **`LF`**
|
||||||
* [Conversions can be chained if invalid](#Substitute-conversions)
|
* [Conversions can be chained if invalid](#substitute-conversions)
|
||||||
* Fast
|
* Fast
|
||||||
|
|
||||||
# Single header
|
# Single header
|
||||||
@@ -378,7 +378,7 @@ if(std::holds_alternative<float>(grade)) {
|
|||||||
```
|
```
|
||||||
## Restrictions
|
## Restrictions
|
||||||
|
|
||||||
Custom **`restrictions`** can be used to narrow down the conversions of unwanted values. **`ss::ir`** (in range) and **`ss::ne`** (none empty) are one of those:
|
Custom **`restrictions`** can be used to narrow down the conversions of unwanted values. **`ss::ir`** (in range) and **`ss::ne`** (none empty) are some of those:
|
||||||
```cpp
|
```cpp
|
||||||
// ss::ne makes sure that the name is not empty
|
// ss::ne makes sure that the name is not empty
|
||||||
// ss::ir makes sure that the grade will be in range [0, 10]
|
// ss::ir makes sure that the grade will be in range [0, 10]
|
||||||
@@ -472,7 +472,6 @@ The delimiter is " ", and the number of columns varies depending on which shape
|
|||||||
```cpp
|
```cpp
|
||||||
ss::parser p{"shapes.txt", " "};
|
ss::parser p{"shapes.txt", " "};
|
||||||
if (!p.valid()) {
|
if (!p.valid()) {
|
||||||
std::cout << p.error_msg() << std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ private:
|
|||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
const split_data& resplit(line_ptr_type new_line, ssize_t new_size,
|
const split_data& resplit(line_ptr_type new_line, ssize_t new_size,
|
||||||
const std::string& delim = default_delimiter) {
|
const std::string& delim) {
|
||||||
return splitter_.resplit(new_line, new_size, delim);
|
return splitter_.resplit(new_line, new_size, delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public:
|
|||||||
struct iterable {
|
struct iterable {
|
||||||
struct iterator {
|
struct iterator {
|
||||||
using value = std::conditional_t<get_object, T,
|
using value = std::conditional_t<get_object, T,
|
||||||
no_void_validator_tup_t<T, Ts...>>;
|
no_void_validator_tup_t<T, Ts...>>;
|
||||||
|
|
||||||
iterator() : parser_{nullptr} {
|
iterator() : parser_{nullptr} {
|
||||||
}
|
}
|
||||||
@@ -623,7 +623,8 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next_line_converter_.resplit(next_line_buffer_, size);
|
next_line_converter_.resplit(next_line_buffer_, size,
|
||||||
|
delim_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,10 +109,10 @@ struct get_matcher<Matcher, T, Ts...> {
|
|||||||
struct is_matcher : is_instance_of_matcher<U, Matcher> {};
|
struct is_matcher : is_instance_of_matcher<U, Matcher> {};
|
||||||
|
|
||||||
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
||||||
"the same matcher is cannot"
|
"the same matcher cannot"
|
||||||
"be defined multiple times");
|
"be defined multiple times");
|
||||||
using type = std::conditional_t<is_matcher<T>::value, T,
|
using type = std::conditional_t<is_matcher<T>::value, T,
|
||||||
typename get_matcher<Matcher, Ts...>::type>;
|
typename get_matcher<Matcher, Ts...>::type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <template <char...> class Matcher>
|
template <template <char...> class Matcher>
|
||||||
@@ -150,7 +150,7 @@ struct get_multiline;
|
|||||||
template <typename T, typename... Ts>
|
template <typename T, typename... Ts>
|
||||||
struct get_multiline<T, Ts...> {
|
struct get_multiline<T, Ts...> {
|
||||||
using type = std::conditional_t<is_instance_of_multiline<T>::value, T,
|
using type = std::conditional_t<is_instance_of_multiline<T>::value, T,
|
||||||
typename get_multiline<Ts...>::type>;
|
typename get_multiline<Ts...>::type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|||||||
16
ssp.hpp
16
ssp.hpp
@@ -17,6 +17,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#define SSP_DISABLE_FAST_FLOAT
|
#define SSP_DISABLE_FAST_FLOAT
|
||||||
|
|
||||||
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
@@ -394,6 +395,7 @@ T to_object(U&& data) {
|
|||||||
|
|
||||||
} /* trait */
|
} /* trait */
|
||||||
|
|
||||||
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
@@ -775,7 +777,7 @@ struct get_matcher<Matcher, T, Ts...> {
|
|||||||
struct is_matcher : is_instance_of_matcher<U, Matcher> {};
|
struct is_matcher : is_instance_of_matcher<U, Matcher> {};
|
||||||
|
|
||||||
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
||||||
"the same matcher is cannot"
|
"the same matcher cannot"
|
||||||
"be defined multiple times");
|
"be defined multiple times");
|
||||||
using type = std::conditional_t<is_matcher<T>::value, T,
|
using type = std::conditional_t<is_matcher<T>::value, T,
|
||||||
typename get_matcher<Matcher, Ts...>::type>;
|
typename get_matcher<Matcher, Ts...>::type>;
|
||||||
@@ -1380,6 +1382,7 @@ public:
|
|||||||
|
|
||||||
} /* ss */
|
} /* ss */
|
||||||
|
|
||||||
|
|
||||||
#ifndef SSP_DISABLE_FAST_FLOAT
|
#ifndef SSP_DISABLE_FAST_FLOAT
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
@@ -1909,7 +1912,7 @@ private:
|
|||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
const split_data& resplit(line_ptr_type new_line, ssize_t new_size,
|
const split_data& resplit(line_ptr_type new_line, ssize_t new_size,
|
||||||
const std::string& delim = default_delimiter) {
|
const std::string& delim) {
|
||||||
return splitter_.resplit(new_line, new_size, delim);
|
return splitter_.resplit(new_line, new_size, delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2198,6 +2201,7 @@ private:
|
|||||||
|
|
||||||
} /* ss */
|
} /* ss */
|
||||||
|
|
||||||
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
template <typename... Matchers>
|
template <typename... Matchers>
|
||||||
@@ -2339,9 +2343,8 @@ public:
|
|||||||
template <bool get_object, typename T, typename... Ts>
|
template <bool get_object, typename T, typename... Ts>
|
||||||
struct iterable {
|
struct iterable {
|
||||||
struct iterator {
|
struct iterator {
|
||||||
using value =
|
using value = std::conditional_t<get_object, T,
|
||||||
std::conditional_t<get_object, T,
|
no_void_validator_tup_t<T, Ts...>>;
|
||||||
no_void_validator_tup_t<T, Ts...>>;
|
|
||||||
|
|
||||||
iterator() : parser_{nullptr} {
|
iterator() : parser_{nullptr} {
|
||||||
}
|
}
|
||||||
@@ -2812,7 +2815,8 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next_line_converter_.resplit(next_line_buffer_, size);
|
next_line_converter_.resplit(next_line_buffer_, size,
|
||||||
|
delim_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user