提交 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) { ...@@ -447,21 +447,37 @@ std::vector<std::string> split(const std::string &s, char delim) {
vector<string> Tokenize(string line) { vector<string> Tokenize(string line) {
vector<string> tokens; vector<string> tokens;
stringstream token; 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); char c = *(sit);
if (isspace(c) && token.str().length() > 0) { if (isspace(c) && token.str().length() > 0) {
tokens.push_back(token.str()); tokens.push_back(token.str());
token.str(""); token.str("");
} else if (c == '\'' || c == '\"') { } else if (c == '\'' || c == '\"') {
char endQuote = c; char endQuote = c;
while (++sit != line.end()) { string::const_iterator endQuoteIt = sit;
if (*sit == endQuote) break; while (++endQuoteIt != line.end()) {
token << *sit; 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 { } else {
token << c; token << c;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册