]> granicus.if.org Git - icinga2/commitdiff
Array: Move Join into the base class, available for programmers
authorMichael Friedrich <michael.friedrich@icinga.com>
Fri, 12 Jul 2019 12:36:55 +0000 (14:36 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Fri, 12 Jul 2019 12:36:55 +0000 (14:36 +0200)
lib/base/array-script.cpp
lib/base/array.cpp
lib/base/array.hpp

index fa7a52dcb794d74499e5d57ebe8a702df5446ad9..1c00f11067f0f563e60a816aa52abbd298405568 100644 (file)
@@ -107,22 +107,7 @@ static Value ArrayJoin(const Value& separator)
        ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
        Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
        REQUIRE_NOT_NULL(self);
-
-       Value result;
-       bool first = true;
-
-       ObjectLock olock(self);
-       for (const Value& item : self) {
-               if (first) {
-                       first = false;
-               } else {
-                       result = result + separator;
-               }
-
-               result = result + item;
-       }
-
-       return result;
+       return self->Join(separator);
 }
 
 static Array::Ptr ArrayReverse()
index d9f360c77187af0f34390ed0c202b8f11cbc6239..08e06fad2d2d310fabd7f36f6be6f89bbd93304a 100644 (file)
@@ -297,6 +297,26 @@ String Array::ToString() const
        return msgbuf.str();
 }
 
+Value Array::Join(const Value& separator) const
+{
+       Value result;
+       bool first = true;
+
+       ObjectLock olock(this);
+
+       for (const Value& item : m_Data) {
+               if (first) {
+                       first = false;
+               } else {
+                       result = result + separator;
+               }
+
+               result = result + item;
+       }
+
+       return result;
+}
+
 Array::Ptr Array::Unique() const
 {
        std::set<Value> result;
index eaecfdf243134ec7777782233eb79d3d4888a94b..2c9a9dda7f7da87f53f17b3ccd441b9397996245 100644 (file)
@@ -94,6 +94,7 @@ public:
        void Sort(bool overrideFrozen = false);
 
        String ToString() const override;
+       Value Join(const Value& separator) const;
 
        Array::Ptr Unique() const;
        void Freeze();