浏览代码

Move the EscapeJSON method to a sharable location.

Stephen Kelly 13 年之前
父节点
当前提交
2c04bc00a4
共有 3 个文件被更改,包括 21 次插入15 次删除
  1. 13 0
      Source/cmGlobalGenerator.cxx
  2. 2 0
      Source/cmGlobalGenerator.h
  3. 6 15
      Source/cmGlobalUnixMakefileGenerator3.cxx

+ 13 - 0
Source/cmGlobalGenerator.cxx

@@ -2474,3 +2474,16 @@ void cmGlobalGenerator::WriteSummary(cmTarget* target)
     cmSystemTools::RemoveFile(file.c_str());
     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;
+}

+ 2 - 0
Source/cmGlobalGenerator.h

@@ -280,6 +280,8 @@ public:
   /** Generate an <output>.rule file path for a given command output.  */
   /** Generate an <output>.rule file path for a given command output.  */
   virtual std::string GenerateRuleFile(std::string const& output) const;
   virtual std::string GenerateRuleFile(std::string const& output) const;
 
 
+  static std::string EscapeJSON(const std::string& s);
+
 protected:
 protected:
   typedef std::vector<cmLocalGenerator*> GeneratorVector;
   typedef std::vector<cmLocalGenerator*> GeneratorVector;
   // for a project collect all its targets by following depend
   // for a project collect all its targets by following depend

+ 6 - 15
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()
 void cmGlobalUnixMakefileGenerator3::Generate()
 {
 {
   // first do superclass method
   // first do superclass method
@@ -179,11 +167,14 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
     *this->CommandDatabase << "," << std::endl;
     *this->CommandDatabase << "," << std::endl;
     }
     }
   *this->CommandDatabase << "{" << std::endl
   *this->CommandDatabase << "{" << std::endl
-      << "  \"directory\": \"" << EscapeJSON(workingDirectory) << "\","
+      << "  \"directory\": \""
+      << cmGlobalGenerator::EscapeJSON(workingDirectory) << "\","
       << std::endl
       << std::endl
-      << "  \"command\": \"" << EscapeJSON(compileCommand) << "\","
+      << "  \"command\": \"" <<
+      cmGlobalGenerator::EscapeJSON(compileCommand) << "\","
       << std::endl
       << std::endl
-      << "  \"file\": \"" << EscapeJSON(sourceFile) << "\""
+      << "  \"file\": \"" <<
+      cmGlobalGenerator::EscapeJSON(sourceFile) << "\""
       << std::endl << "}";
       << std::endl << "}";
 }
 }