compared using the `<` (less-than) operator. A custom comparator function
can be specified with the `less_cmp` argument.
+### <a id="array-join"></a> Array#join
+
+Signature:
+
+ function join(separator);
+
+Joins all elements of the array using the specified separator.
+
## <a id="dictionary-type"></a> Dictionary type
### <a id="dictionary-clone"></a> Dictionary#clone
#include "base/functionwrapper.hpp"
#include "base/scriptframe.hpp"
#include "base/objectlock.hpp"
+#include <boost/foreach.hpp>
using namespace icinga;
return self->ShallowClone();
}
+static Value ArrayJoin(const Value& separator)
+{
+ ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+ Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
+
+ Value result;
+ bool first = true;
+
+ ObjectLock olock(self);
+ BOOST_FOREACH(const Value& item, self) {
+ if (first) {
+ first = false;
+ } else {
+ result = result + separator;
+ }
+
+ result = result + item;
+ }
+
+ return result;
+}
+
Object::Ptr Array::GetPrototype(void)
{
static Dictionary::Ptr prototype;
prototype->Set("clear", new Function(WrapFunction(ArrayClear)));
prototype->Set("sort", new Function(WrapFunction(ArraySort)));
prototype->Set("clone", new Function(WrapFunction(ArrayClone)));
+ prototype->Set("join", new Function(WrapFunction(ArrayJoin)));
}
return prototype;