10
10
11
11
#include " typetraits.h"
12
12
13
+ void removeOuterSpaces (std::string& value) {
14
+ const auto start = value.find_first_not_of (' ' );
15
+ const auto end = value.find_last_not_of (' ' );
16
+ value = value.substr (start, end - start + 1 );
17
+ }
18
+
13
19
bool hasEncapsulatedTokens (const std::string& str, char start, char end) {
14
20
if (str.empty ()) {
15
21
return false ;
@@ -72,6 +78,7 @@ std::vector<std::string> splitIgnoreBrackets(const std::string& str,
72
78
73
79
template <typename T>
74
80
std::enable_if_t <std::is_same_v<char , T>, T> parse (std::string& value) {
81
+ removeOuterSpaces (value);
75
82
if (value.size () != 3 || !isCharFormatOk (value)) {
76
83
std::stringstream ss;
77
84
ss << " Error: Invalid char format. Must be of length 3 and contain "
@@ -83,26 +90,30 @@ std::enable_if_t<std::is_same_v<char, T>, T> parse(std::string& value) {
83
90
84
91
template <typename T>
85
92
std::enable_if_t <std::is_same_v<std::string, T>, T> parse (std::string& value) {
93
+ removeOuterSpaces (value);
86
94
if (!isStringFormatOk (value)) {
87
95
std::stringstream ss;
88
- ss << " Error: Invalid string format. Must contain \" s. String: "
89
- << value;
96
+ ss << " Error: Invalid string format. The input string must be enclosed "
97
+ " in quotes. Current value: " << value;
90
98
throw std::runtime_error (ss.str ());
91
99
}
92
100
return removeQuotes (value);
93
101
}
94
102
95
103
template <typename T>
96
104
std::enable_if_t <std::is_integral_v<T>, T> parse (const std::string& value) {
105
+ std::string valueCopy = value;
106
+ removeOuterSpaces (valueCopy);
97
107
T ret{};
98
- std::stringstream ss (value );
108
+ std::stringstream ss (valueCopy );
99
109
ss >> ret;
100
110
return ret;
101
111
}
102
112
103
113
template <typename T>
104
114
std::enable_if_t <is_vector_type<T>::value, T> parse (auto && value) {
105
115
using element_type = typename T::value_type;
116
+ removeOuterSpaces (value);
106
117
T vec;
107
118
if (!isArrayFormatOk (value)) {
108
119
std::stringstream ss;
0 commit comments