Fixed #8864 (compile commands: handle define with string value)
This commit is contained in:
parent
33027dc10b
commit
86f9fb778b
|
@ -248,20 +248,16 @@ void ImportProject::importCompileCommands(std::istream &istr)
|
||||||
}
|
}
|
||||||
if (F=='D') {
|
if (F=='D') {
|
||||||
std::string defval;
|
std::string defval;
|
||||||
bool escape = false;
|
bool str = false;
|
||||||
while (pos < command.size() && command[pos] != ' ') {
|
while (pos < command.size() && (str || command[pos] != ' ')) {
|
||||||
if (command[pos] != '\\') {
|
if (command.compare(pos, 4, "\\\\\\\"") == 0) {
|
||||||
defval += command[pos];
|
defval += '\"';
|
||||||
escape = false;
|
str = !str;
|
||||||
|
pos += 4;
|
||||||
} else {
|
} else {
|
||||||
if (escape) {
|
defval += command[pos];
|
||||||
defval += '\\';
|
pos++;
|
||||||
escape = false;
|
|
||||||
} else {
|
|
||||||
escape = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pos++;
|
|
||||||
}
|
}
|
||||||
fs.defines += fval;
|
fs.defines += fval;
|
||||||
if (!defval.empty())
|
if (!defval.empty())
|
||||||
|
|
|
@ -94,13 +94,13 @@ private:
|
||||||
void importCompileCommands() const {
|
void importCompileCommands() const {
|
||||||
|
|
||||||
const char json[] = "[ { \"directory\": \"/tmp\","
|
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\" } ]";
|
"\"file\": \"/tmp/src.c\" } ]";
|
||||||
std::istringstream istr(json);
|
std::istringstream istr(json);
|
||||||
TestImporter importer;
|
TestImporter importer;
|
||||||
importer.importCompileCommands(istr);
|
importer.importCompileCommands(istr);
|
||||||
ASSERT_EQUALS(1, importer.fileSettings.size());
|
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