Skip to content

Commit e5cab40

Browse files
committed
Allow leading plus signs when parsing integers.
1 parent 9333ec0 commit e5cab40

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

include/eminem/Parser.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,11 +1372,9 @@ class Parser {
13721372
public:
13731373
template<class Input2_>
13741374
ParseInfo<Type_> operator()(Input2_& input, Index overall_line_count) {
1375-
Type_ val = 0;
1376-
bool found = false;
1377-
1378-
bool negative = (input.get() == '-');
1379-
if (negative) {
1375+
char firstchar = input.get();
1376+
bool negative = (firstchar == '-');
1377+
if (negative || firstchar == '+') {
13801378
if (!(input.advance())) {
13811379
throw std::runtime_error("premature termination of an integer on line " + std::to_string(overall_line_count + 1));
13821380
}
@@ -1389,6 +1387,8 @@ class Parser {
13891387
constexpr Type_ lower_limit_before_mult = lower_limit / 10;
13901388
constexpr Type_ lower_limit_mod = -(lower_limit % 10);
13911389

1390+
Type_ val = 0;
1391+
bool found = false;
13921392
while (1) {
13931393
char x = input.get();
13941394
switch (x) {

tests/src/integer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ INSTANTIATE_TEST_SUITE_P(
5050
std::make_tuple<std::string, int, int, std::vector<int> >("1 1 -1\n2 2 -23\n3 3 -456\n4 4 -7890\n", 5, 5, { -1, -23, -456, -7890 }), // negative values
5151
std::make_tuple<std::string, int, int, std::vector<int> >("12 34 567890", 50, 50, { 567890 }), // no trailing newline
5252
std::make_tuple<std::string, int, int, std::vector<int> >("12 34 567890 ", 50, 50, { 567890 }), // trailing blank without a trailing newline.
53-
std::make_tuple<std::string, int, int, std::vector<int> >("1 1 11 \n2 22 2222\n33 3\t33\t\n44 44 \t4\t \n", 100, 100, { 11, 2222, 33, 4 }) // variable numbers of blanks
53+
std::make_tuple<std::string, int, int, std::vector<int> >("1 1 11 \n2 22 2222\n33 3\t33\t\n44 44 \t4\t \n", 100, 100, { 11, 2222, 33, 4 }), // variable numbers of blanks
54+
std::make_tuple<std::string, int, int, std::vector<int> >("1 1 0111\n2 22 +002\n33 3 033\t\n44 44 +0004\n", 100, 100, { 111, 2, 33, 4 }) // leading zeros and pluses
5455
)
5556
);
5657

0 commit comments

Comments
 (0)