len(value) | Returns the length of the value, i.e. the number of elements for an array or dictionary, or the length of the string in bytes.
union(array, array, ...) | Returns an array containing all unique elements from the specified arrays.
intersection(array, array, ...) | Returns an array containing all unique elements which are common to all specified arrays.
+keys(dict) | Returns an array containing the dictionary's keys.
string(value) | Converts the value to a string.
number(value) | Converts the value to a number.
bool(value) | Converts the value to a bool.
#include "base/scriptfunction.hpp"
#include "base/utility.hpp"
#include "base/convert.hpp"
-#include "base/array.hpp"
-#include "base/dictionary.hpp"
#include "base/json.hpp"
#include "base/logger.hpp"
+#include "base/objectlock.hpp"
#include <boost/foreach.hpp>
#include <boost/regex.hpp>
#include <algorithm>
REGISTER_SCRIPTFUNCTION(range, &ScriptUtils::Range);
REGISTER_SCRIPTFUNCTION(exit, &ScriptUtils::Exit);
REGISTER_SCRIPTFUNCTION(typeof, &ScriptUtils::TypeOf);
+REGISTER_SCRIPTFUNCTION(keys, &ScriptUtils::Keys);
bool ScriptUtils::Regex(const String& pattern, const String& text)
{
VERIFY(!"Invalid value type.");
}
}
+
+Array::Ptr ScriptUtils::Keys(const Dictionary::Ptr& dict)
+{
+ Array::Ptr result = make_shared<Array>();
+
+ ObjectLock olock(dict);
+ BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
+ result->Add(kv.first);
+ }
+
+ return result;
+}
+
#include "base/i2-base.hpp"
#include "base/string.hpp"
#include "base/array.hpp"
+#include "base/dictionary.hpp"
#include "base/type.hpp"
namespace icinga
static Array::Ptr Range(const std::vector<Value>& arguments);
static void Exit(int code);
static Type::Ptr TypeOf(const Value& value);
+ static Array::Ptr Keys(const Dictionary::Ptr& dict);
private:
ScriptUtils(void);