]> granicus.if.org Git - icinga2/commitdiff
Refactor String-Escape in repositoryutility
authorJean Flach <jean-marcel.flach@netways.de>
Tue, 9 Feb 2016 08:38:12 +0000 (09:38 +0100)
committerJean Flach <jean-marcel.flach@netways.de>
Tue, 9 Feb 2016 08:38:12 +0000 (09:38 +0100)
fixes #10989

lib/base/configwriter.hpp
lib/cli/repositoryutility.cpp
lib/cli/repositoryutility.hpp

index 7f746e6af2d035344721ba637a8fc84e43d4b0f9..bc7862a480d7d78708768653457cbe4f88809154 100644 (file)
@@ -73,10 +73,9 @@ public:
        static void EmitFunctionCall(std::ostream& fp, const String& name, const Array::Ptr& arguments);
 
        static const std::vector<String>& GetKeywords(void);
+       static String EscapeIcingaString(const String& str);
 private:
        ConfigWriter(void);
-
-       static String EscapeIcingaString(const String& str);
 };
 
 }
index eabe0bba581ad6f23fe8479c0830a8c4b8cbf993..1f028a9480d2d33e45ee35dd40eb9169421fba3c 100644 (file)
@@ -22,6 +22,7 @@
 #include "base/logger.hpp"
 #include "base/application.hpp"
 #include "base/convert.hpp"
+#include "base/configwriter.hpp"
 #include "base/scriptglobal.hpp"
 #include "base/json.hpp"
 #include "base/netstring.hpp"
@@ -683,7 +684,7 @@ void RepositoryUtility::FormatChangelogEntry(std::ostream& fp, const Dictionary:
  */
 void RepositoryUtility::SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object)
 {
-       fp << "object " << type << " \"" << EscapeIcingaString(name) << "\" {\n";
+       fp << "object " << type << " \"" << ConfigWriter::EscapeIcingaString(name) << "\" {\n";
 
        if (!object) {
                fp << "}\n";
@@ -712,19 +713,6 @@ void RepositoryUtility::SerializeObject(std::ostream& fp, const String& name, co
        fp << "}\n";
 }
 
-String RepositoryUtility::EscapeIcingaString(const String& str)
-{
-       String result = str;
-       boost::algorithm::replace_all(result, "\\", "\\\\");
-       boost::algorithm::replace_all(result, "\n", "\\n");
-       boost::algorithm::replace_all(result, "\t", "\\t");
-       boost::algorithm::replace_all(result, "\r", "\\r");
-       boost::algorithm::replace_all(result, "\b", "\\b");
-       boost::algorithm::replace_all(result, "\f", "\\f");
-       boost::algorithm::replace_all(result, "\"", "\\\"");
-       return result;
-}
-
 void RepositoryUtility::FormatValue(std::ostream& fp, const Value& val)
 {
        if (val.IsObjectType<Array>()) {
@@ -733,11 +721,11 @@ void RepositoryUtility::FormatValue(std::ostream& fp, const Value& val)
        }
 
        if (val.IsString()) {
-               fp << "\"" << EscapeIcingaString(val) << "\"";
+               fp << "\"" << ConfigWriter::EscapeIcingaString(val) << "\"";
                return;
        }
 
-       fp << EscapeIcingaString(val);
+       fp << ConfigWriter::EscapeIcingaString(val);
 }
 
 void RepositoryUtility::FormatArray(std::ostream& fp, const Array::Ptr& arr)
index 02ea03dff5e6b046da1d994a8dd64b9963d1703d..23d2a69267808e34f599d0ab6536e1e28f596a5b 100644 (file)
@@ -96,7 +96,6 @@ private:
 
        /* config print helpers */
        static void SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object);
-       static String EscapeIcingaString(const String& str);
        static void FormatValue(std::ostream& fp, const Value& val);
        static void FormatArray(std::ostream& fp, const Array::Ptr& arr);