From 2c04bc00a4e38fc1b8f15bf950c8c2191ba24eac Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 6 May 2012 15:07:19 +0200 Subject: Move the EscapeJSON method to a sharable location. --- Source/cmGlobalGenerator.cxx | 13 +++++++++++++ Source/cmGlobalGenerator.h | 2 ++ Source/cmGlobalUnixMakefileGenerator3.cxx | 21 ++++++--------------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index b06cdb4..f883041 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2474,3 +2474,16 @@ void cmGlobalGenerator::WriteSummary(cmTarget* target) cmSystemTools::RemoveFile(file.c_str()); } } + +//---------------------------------------------------------------------------- +// static +std::string cmGlobalGenerator::EscapeJSON(const std::string& s) { + std::string result; + for (std::string::size_type i = 0; i < s.size(); ++i) { + if (s[i] == '"' || s[i] == '\\') { + result += '\\'; + } + result += s[i]; + } + return result; +} diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 5254b89..8535edc 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -280,6 +280,8 @@ public: /** Generate an .rule file path for a given command output. */ virtual std::string GenerateRuleFile(std::string const& output) const; + static std::string EscapeJSON(const std::string& s); + protected: typedef std::vector GeneratorVector; // for a project collect all its targets by following depend diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index e63de9c..ebd8219 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -103,18 +103,6 @@ cmGlobalUnixMakefileGenerator3 } } -//---------------------------------------------------------------------------- -std::string EscapeJSON(const std::string& s) { - std::string result; - for (std::string::size_type i = 0; i < s.size(); ++i) { - if (s[i] == '"' || s[i] == '\\') { - result += '\\'; - } - result += s[i]; - } - return result; -} - void cmGlobalUnixMakefileGenerator3::Generate() { // first do superclass method @@ -179,11 +167,14 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand( *this->CommandDatabase << "," << std::endl; } *this->CommandDatabase << "{" << std::endl - << " \"directory\": \"" << EscapeJSON(workingDirectory) << "\"," + << " \"directory\": \"" + << cmGlobalGenerator::EscapeJSON(workingDirectory) << "\"," << std::endl - << " \"command\": \"" << EscapeJSON(compileCommand) << "\"," + << " \"command\": \"" << + cmGlobalGenerator::EscapeJSON(compileCommand) << "\"," << std::endl - << " \"file\": \"" << EscapeJSON(sourceFile) << "\"" + << " \"file\": \"" << + cmGlobalGenerator::EscapeJSON(sourceFile) << "\"" << std::endl << "}"; } -- cgit v0.12