Skip to content

Commit b6eca36

Browse files
committed
Replace existing command parsing
1 parent fc25f54 commit b6eca36

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

lib/importproject.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -495,31 +495,31 @@ bool ImportProject::importCompileCommands(std::istream &istr)
495495

496496
const std::string directory = std::move(dirpath);
497497

498-
bool doUnescape = false;
499-
std::string command;
498+
std::vector<std::string> arguments;
500499
if (obj.count("arguments")) {
501-
doUnescape = false;
502500
if (obj["arguments"].is<picojson::array>()) {
503501
for (const picojson::value& arg : obj["arguments"].get<picojson::array>()) {
504-
if (arg.is<std::string>()) {
505-
std::string str = arg.get<std::string>();
506-
if (str.find(' ') != std::string::npos)
507-
str = "\"" + str + "\"";
508-
command += str + " ";
509-
}
502+
if (arg.is<std::string>())
503+
arguments.push_back(arg.get<std::string>());
510504
}
511505
} else {
512506
errors.emplace_back("'arguments' field in compilation database entry is not a JSON array");
513507
return false;
514508
}
515509
} else if (obj.count("command")) {
516-
doUnescape = true;
510+
std::string command;
517511
if (obj["command"].is<std::string>()) {
518512
command = obj["command"].get<std::string>();
519513
} else {
520514
errors.emplace_back("'command' field in compilation database entry is not a string");
521515
return false;
522516
}
517+
518+
std::string error = collectArgs(command, arguments);
519+
if (!error.empty()) {
520+
errors.emplace_back(error);
521+
return false;
522+
}
523523
} else {
524524
errors.emplace_back("no 'arguments' or 'command' field found in compilation database entry");
525525
return false;
@@ -549,7 +549,7 @@ bool ImportProject::importCompileCommands(std::istream &istr)
549549
else
550550
path = Path::simplifyPath(directory + file);
551551
FileSettings fs{path, Standards::Language::None, 0}; // file will be identified later on
552-
fsParseCommand(fs, command, doUnescape); // read settings; -D, -I, -U, -std, -m*, -f*
552+
parseArgs(fs, arguments);
553553
std::map<std::string, std::string, cppcheck::stricmp> variables;
554554
fsSetIncludePaths(fs, directory, fs.includePaths, variables);
555555
// Assign a unique index to each file path. If the file path already exists in the map,

0 commit comments

Comments
 (0)