bool parseStringInto(std::string &String) {
do {
if (*Position == '"') {
- if (!parseQuotedStringInto(String)) return false;
+ if (!parseDoubleQuotedStringInto(String)) return false;
+ } else if (*Position == '\'') {
+ if (!parseSingleQuotedStringInto(String)) return false;
} else {
if (!parseFreeStringInto(String)) return false;
}
return true;
}
- bool parseQuotedStringInto(std::string &String) {
+ bool parseDoubleQuotedStringInto(std::string &String) {
if (!next()) return false;
while (*Position != '"') {
if (!skipEscapeCharacter()) return false;
return next();
}
+ bool parseSingleQuotedStringInto(std::string &String) {
+ if (!next()) return false;
+ while (*Position != '\'') {
+ String.push_back(*Position);
+ if (!next()) return false;
+ }
+ return next();
+ }
+
bool parseFreeStringInto(std::string &String) {
do {
if (!skipEscapeCharacter()) return false;
String.push_back(*Position);
if (!next()) return false;
- } while (*Position != ' ' && *Position != '"');
+ } while (*Position != ' ' && *Position != '"' && *Position != '\'');
return true;
}
EXPECT_EQ("", Empty[0]);
}
+TEST(unescapeJsonCommandLine, ParsesSingleQuotedString) {
+ std::vector<std::string> Args = unescapeJsonCommandLine("a'\\\\b \\\"c\\\"'");
+ ASSERT_EQ(1ul, Args.size());
+ EXPECT_EQ("a\\b \"c\"", Args[0]);
+}
+
TEST(FixedCompilationDatabase, ReturnsFixedCommandLine) {
std::vector<std::string> CommandLine;
CommandLine.push_back("one");