Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b70025b

Browse files
committed
Remove leading and trailing spaces from testcase input.
1 parent 3f32d7d commit b70025b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

‎data/languages/cpp/parser.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
#include "typetraits.h"
1212

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+
1319
bool hasEncapsulatedTokens(const std::string& str, char start, char end) {
1420
if (str.empty()) {
1521
return false;
@@ -72,6 +78,7 @@ std::vector<std::string> splitIgnoreBrackets(const std::string& str,
7278

7379
template <typename T>
7480
std::enable_if_t<std::is_same_v<char, T>, T> parse(std::string& value) {
81+
removeOuterSpaces(value);
7582
if (value.size() != 3 || !isCharFormatOk(value)) {
7683
std::stringstream ss;
7784
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) {
8390

8491
template <typename T>
8592
std::enable_if_t<std::is_same_v<std::string, T>, T> parse(std::string& value) {
93+
removeOuterSpaces(value);
8694
if (!isStringFormatOk(value)) {
8795
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;
9098
throw std::runtime_error(ss.str());
9199
}
92100
return removeQuotes(value);
93101
}
94102

95103
template <typename T>
96104
std::enable_if_t<std::is_integral_v<T>, T> parse(const std::string& value) {
105+
std::string valueCopy = value;
106+
removeOuterSpaces(valueCopy);
97107
T ret{};
98-
std::stringstream ss(value);
108+
std::stringstream ss(valueCopy);
99109
ss >> ret;
100110
return ret;
101111
}
102112

103113
template <typename T>
104114
std::enable_if_t<is_vector_type<T>::value, T> parse(auto&& value) {
105115
using element_type = typename T::value_type;
116+
removeOuterSpaces(value);
106117
T vec;
107118
if (!isArrayFormatOk(value)) {
108119
std::stringstream ss;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /