diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-03-02 03:07:10 -0600 |
---|---|---|
committer | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-03-15 09:20:15 -0500 |
commit | 66c46eb3e51f2f26b43d23b1b734a29346069d72 (patch) | |
tree | 1427cbdcd87c3e621e6929008b887c797501d939 | |
parent | a87c157c31eab93aa31884de7d5ad5aa3bd7fe23 (diff) | |
download | phosphor-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.hpp | 21 |
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 |