@@ -256,7 +256,7 @@ static std::string unescape(const std::string &in)
256256 return out;
257257}
258258
259- void ImportProject::fsParseCommand (FileSettings& fs, const std::string& command)
259+ void ImportProject::fsParseCommand (FileSettings& fs, const std::string& command, bool doUnescape )
260260{
261261 std::string defs;
262262
@@ -281,10 +281,12 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command)
281281 if (F==' D' ) {
282282 std::string defval = readUntil (command, &pos, " " );
283283 defs += fval;
284- if (defval.size () >= 3 && startsWith (defval," =\" " ) && defval.back ()==' \" ' )
285- defval = " =" + unescape (defval.substr (2 , defval.size () - 3 ));
286- else if (defval.size () >= 5 && startsWith (defval, " =\\\" " ) && endsWith (defval, " \\\" " ))
287- defval = " =\" " + unescape (defval.substr (3 , defval.size () - 5 )) + " \" " ;
284+ if (doUnescape) {
285+ if (defval.size () >= 3 && startsWith (defval," =\" " ) && defval.back ()==' \" ' )
286+ defval = " =" + unescape (defval.substr (2 , defval.size () - 3 ));
287+ else if (defval.size () >= 5 && startsWith (defval, " =\\\" " ) && endsWith (defval, " \\\" " ))
288+ defval = " =\" " + unescape (defval.substr (3 , defval.size () - 5 )) + " \" " ;
289+ }
288290 if (!defval.empty ())
289291 defs += defval;
290292 defs += ' ;' ;
@@ -362,8 +364,10 @@ bool ImportProject::importCompileCommands(std::istream &istr)
362364
363365 const std::string directory = std::move (dirpath);
364366
367+ bool doUnescape = false ;
365368 std::string command;
366369 if (obj.count (" arguments" )) {
370+ doUnescape = false ;
367371 if (obj[" arguments" ].is <picojson::array>()) {
368372 for (const picojson::value& arg : obj[" arguments" ].get <picojson::array>()) {
369373 if (arg.is <std::string>()) {
@@ -378,6 +382,7 @@ bool ImportProject::importCompileCommands(std::istream &istr)
378382 return false ;
379383 }
380384 } else if (obj.count (" command" )) {
385+ doUnescape = true ;
381386 if (obj[" command" ].is <std::string>()) {
382387 command = obj[" command" ].get <std::string>();
383388 } else {
@@ -413,7 +418,7 @@ bool ImportProject::importCompileCommands(std::istream &istr)
413418 else
414419 path = Path::simplifyPath (directory + file);
415420 FileSettings fs{path, Standards::Language::None, 0 }; // file will be identified later on
416- fsParseCommand (fs, command); // read settings; -D, -I, -U, -std, -m*, -f*
421+ fsParseCommand (fs, command, doUnescape ); // read settings; -D, -I, -U, -std, -m*, -f*
417422 std::map<std::string, std::string, cppcheck::stricmp> variables;
418423 fsSetIncludePaths (fs, directory, fs.includePaths , variables);
419424 // Assign a unique index to each file path. If the file path already exists in the map,
0 commit comments