Fixed #8864 (compile commands: handle define with string value)
This commit is contained in:
parent
33027dc10b
commit
86f9fb778b
|
@ -248,21 +248,17 @@ void ImportProject::importCompileCommands(std::istream &istr)
|
|||
}
|
||||
if (F=='D') {
|
||||
std::string defval;
|
||||
bool escape = false;
|
||||
while (pos < command.size() && command[pos] != ' ') {
|
||||
if (command[pos] != '\\') {
|
||||
bool str = false;
|
||||
while (pos < command.size() && (str || command[pos] != ' ')) {
|
||||
if (command.compare(pos, 4, "\\\\\\\"") == 0) {
|
||||
defval += '\"';
|
||||
str = !str;
|
||||
pos += 4;
|
||||
} else {
|
||||
defval += command[pos];
|
||||
escape = false;
|
||||
} else {
|
||||
if (escape) {
|
||||
defval += '\\';
|
||||
escape = false;
|
||||
} else {
|
||||
escape = true;
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
fs.defines += fval;
|
||||
if (!defval.empty())
|
||||
fs.defines += defval;
|
||||
|
|
|
@ -94,13 +94,13 @@ private:
|
|||
void importCompileCommands() const {
|
||||
|
||||
const char json[] = "[ { \"directory\": \"/tmp\","
|
||||
"\"command\": \"gcc -I/tmp -DTEST1 -DTEST2=2 -DTEST3=\\\"\\\\\\\"3\\\\\\\"\\\" -o /tmp/src.o -c /tmp/src.c\","
|
||||
"\"command\": \"gcc -I/tmp -DCFGDIR=\\\\\\\"/usr/local/share/Cppcheck\\\\\\\" -DTEST1 -DTEST2=2 -o /tmp/src.o -c /tmp/src.c\","
|
||||
"\"file\": \"/tmp/src.c\" } ]";
|
||||
std::istringstream istr(json);
|
||||
TestImporter importer;
|
||||
importer.importCompileCommands(istr);
|
||||
ASSERT_EQUALS(1, importer.fileSettings.size());
|
||||
ASSERT_EQUALS("TEST1=1;TEST2=2;TEST3=\"\\\"3\\\"\"", importer.fileSettings.begin()->defines);
|
||||
ASSERT_EQUALS("CFGDIR=\"/usr/local/share/Cppcheck\";TEST1=1;TEST2=2", importer.fileSettings.begin()->defines);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue