提交 5e05dad8 编写于 作者: J jonathan pickett

issue 153: command line parsing dying on imbalanced quotes in comments

上级 192b285b
......@@ -447,21 +447,37 @@ std::vector<std::string> split(const std::string &s, char delim) {
vector<string> Tokenize(string line) {
vector<string> tokens;
stringstream token;
for (string::iterator sit = line.begin(); sit != line.end(); sit++) {
// no need to parse empty lines, or comment lines (which may have unbalanced quotes)
if ((line.length() == 0) ||
((line.length() != 0) && (*line.begin()) == '#')) {
return tokens;
}
for (string::const_iterator sit = line.begin(); sit != line.end(); sit++) {
char c = *(sit);
if (isspace(c) && token.str().length() > 0) {
tokens.push_back(token.str());
token.str("");
} else if (c == '\'' || c == '\"') {
char endQuote = c;
while (++sit != line.end()) {
if (*sit == endQuote) break;
token << *sit;
string::const_iterator endQuoteIt = sit;
while (++endQuoteIt != line.end()) {
if (*endQuoteIt == endQuote) break;
}
if (endQuoteIt != line.end()) {
while (++sit != endQuoteIt) {
token << (*sit);
}
string path = token.str();
replace(path.begin(), path.end(), '/', '\\');
tokens.push_back(path);
token.str("");
} else {
// stuff the imbalanced quote character and continue
token << (*sit);
}
string path = token.str();
replace(path.begin(), path.end(), '/', '\\');
tokens.push_back(path);
token.str("");
} else {
token << c;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册