-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing empty vector in parameter. (#5087)
- Loading branch information
1 parent
f5e13dc
commit df9bdbb
Showing
4 changed files
with
89 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/*! | ||
* Copyright by Contributors 2019 | ||
*/ | ||
#include <iostream> | ||
#include <vector> | ||
#include <utility> | ||
|
||
#include "param.h" | ||
|
||
namespace std { | ||
std::istream &operator>>(std::istream &is, std::vector<int> &t) { | ||
t.clear(); | ||
// get ( | ||
while (true) { | ||
char ch = is.peek(); | ||
if (isdigit(ch)) { | ||
int idx; | ||
if (is >> idx) { | ||
t.emplace_back(idx); | ||
} | ||
return is; | ||
} | ||
is.get(); | ||
if (ch == '(') { | ||
break; | ||
} | ||
if (!isspace(ch)) { | ||
is.setstate(std::ios::failbit); | ||
return is; | ||
} | ||
} | ||
int idx; | ||
std::vector<int> tmp; | ||
while (true) { | ||
char ch = is.peek(); | ||
if (isspace(ch)) { | ||
is.get(); | ||
} else { | ||
break; | ||
} | ||
} | ||
if (is.peek() == ')') { | ||
is.get(); | ||
return is; | ||
} | ||
while (is >> idx) { | ||
tmp.push_back(idx); | ||
char ch; | ||
do { | ||
ch = is.get(); | ||
} while (isspace(ch)); | ||
if (ch == 'L') { | ||
ch = is.get(); | ||
} | ||
if (ch == ',') { | ||
while (true) { | ||
ch = is.peek(); | ||
if (isspace(ch)) { | ||
is.get(); | ||
continue; | ||
} | ||
if (ch == ')') { | ||
is.get(); | ||
break; | ||
} | ||
break; | ||
} | ||
if (ch == ')') { | ||
break; | ||
} | ||
} else if (ch == ')') { | ||
break; | ||
} else { | ||
is.setstate(std::ios::failbit); | ||
return is; | ||
} | ||
} | ||
t = std::move(tmp); | ||
return is; | ||
} | ||
} // namespace std |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters