summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-03-02 03:07:10 -0600
committerDeepak Kodihalli <dkodihal@in.ibm.com>2017-03-15 09:20:15 -0500
commit66c46eb3e51f2f26b43d23b1b734a29346069d72 (patch)
tree1427cbdcd87c3e621e6929008b887c797501d939
parenta87c157c31eab93aa31884de7d5ad5aa3bd7fe23 (diff)
downloadphosphor-logging-66c46eb3e51f2f26b43d23b1b734a29346069d72.tar.gz
phosphor-logging-66c46eb3e51f2f26b43d23b1b734a29346069d72.zip
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>
-rw-r--r--elog_meta.hpp21
1 files changed, 21 insertions, 0 deletions
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 @@ using Type = void(const std::string&,
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
OpenPOWER on IntegriCloud