Add utility to parse error metadata
Add method to parse out the metadata name and value from the error
metadata, which is of the format "name=value".
Change-Id: I7b6ba790c97faced664a11eb5806f7f87e8166a7
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/elog_meta.hpp b/elog_meta.hpp
index 0c3c353..f5c6f4c 100644
--- a/elog_meta.hpp
+++ b/elog_meta.hpp
@@ -21,6 +21,27 @@
const std::vector<std::string>&,
AssociationList& list);
+/** @brief Pull out metadata name and value from the string
+ * <metadata name>=<metadata value>
+ * @param [in] data - metadata key=value entries
+ * @param [out] metadata - map of metadata name:value
+ */
+inline void parse(const std::vector<std::string>& data,
+ std::map<std::string, std::string>& metadata)
+{
+ constexpr auto separator = '=';
+ for(const auto& entry: data)
+ {
+ auto pos = entry.find(separator);
+ if(std::string::npos != pos)
+ {
+ auto key = entry.substr(0, entry.find(separator));
+ auto value = entry.substr(entry.find(separator) + 1);
+ metadata.emplace(std::move(key), std::move(value));
+ }
+ }
+};
+
/** @brief Build error associations specific to metadata. Specialize this
* template for handling a specific type of metadata.
* @tparam M - type of metadata