refactor metadata pack/unpack functions

Move the `parse` and `combine` functions, which are used to translate
between `map<string,string>` and `vector<string>` for the metadata.
This is in preparation for transitioning the AdditionalData field
from `vector` to `map`.

Tested: Test cases pass.  Simple `log-create` call has no change in
behavior.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ib968e1fe02903072c300d5387cf91f2d8164b1b4
diff --git a/util.cpp b/util.cpp
index da068e6..3847e0a 100644
--- a/util.cpp
+++ b/util.cpp
@@ -197,4 +197,42 @@
     return;
 }
 
+namespace additional_data
+{
+auto parse(const std::vector<std::string>& data)
+    -> std::map<std::string, std::string>
+{
+    std::map<std::string, std::string> metadata{};
+
+    constexpr auto separator = '=';
+    for (const auto& entryItem : data)
+    {
+        auto pos = entryItem.find(separator);
+        if (std::string::npos != pos)
+        {
+            auto key = entryItem.substr(0, entryItem.find(separator));
+            auto value = entryItem.substr(entryItem.find(separator) + 1);
+            metadata.emplace(std::move(key), std::move(value));
+        }
+    }
+
+    return metadata;
+}
+
+auto combine(const std::map<std::string, std::string>& data)
+    -> std::vector<std::string>
+{
+    std::vector<std::string> metadata{};
+
+    for (const auto& [key, value] : data)
+    {
+        std::string line{key};
+        line += "=" + value;
+        metadata.emplace_back(std::move(line));
+    }
+
+    return metadata;
+}
+} // namespace additional_data
+
 } // namespace phosphor::logging::util