Abstract fillMessageArgs and unit test it

EventService has a routine for taking a message registry entry and
populate it with data.  This ideally should be part of the message
registry namespace, not EventService, as it could be useful to later
patchsets.  So break out the method, and write some unit tests to ensure
that it can be relied upon in the future.

Tested: Unit tests ran and passing.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I052d9492f306b63fb72cbf78286370ed0c477430
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 3429c02..55485c6 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -223,7 +223,7 @@
 
 inline int formatEventLogEntry(const std::string& logEntryID,
                                const std::string& messageID,
-                               const std::vector<std::string>& messageArgs,
+                               const std::span<std::string_view> messageArgs,
                                std::string timestamp,
                                const std::string& customText,
                                nlohmann::json& logEntryJson)
@@ -240,17 +240,7 @@
         severity = message->severity;
     }
 
-    // Fill the MessageArgs into the Message
-    int i = 0;
-    for (const std::string& messageArg : messageArgs)
-    {
-        std::string argStr = "%" + std::to_string(++i);
-        size_t argPos = msg.find(argStr);
-        if (argPos != std::string::npos)
-        {
-            msg.replace(argPos, argStr.length(), messageArg);
-        }
-    }
+    redfish::message_registries::fillMessageArgs(messageArgs, msg);
 
     // Get the Created time from the timestamp. The log timestamp is in
     // RFC3339 format which matches the Redfish format except for the
@@ -482,11 +472,14 @@
                 }
             }
 
+            std::vector<std::string_view> messageArgsView(messageArgs.begin(),
+                                                          messageArgs.end());
+
             logEntryArray.push_back({});
             nlohmann::json& bmcLogEntry = logEntryArray.back();
-            if (event_log::formatEventLogEntry(idStr, messageID, messageArgs,
-                                               timestamp, customText,
-                                               bmcLogEntry) != 0)
+            if (event_log::formatEventLogEntry(idStr, messageID,
+                                               messageArgsView, timestamp,
+                                               customText, bmcLogEntry) != 0)
             {
                 BMCWEB_LOG_DEBUG << "Read eventLog entry failed";
                 continue;
diff --git a/redfish-core/include/registries.hpp b/redfish-core/include/registries.hpp
index e326323..f85d2a5 100644
--- a/redfish-core/include/registries.hpp
+++ b/redfish-core/include/registries.hpp
@@ -14,6 +14,11 @@
 // limitations under the License.
 */
 #pragma once
+
+#include <span>
+#include <string>
+#include <string_view>
+
 namespace redfish::message_registries
 {
 struct Header
@@ -40,4 +45,21 @@
     const char* resolution;
 };
 using MessageEntry = std::pair<const char*, const Message>;
+
+inline void fillMessageArgs(const std::span<const std::string_view> messageArgs,
+                            std::string& msg)
+{
+    int i = 0;
+    for (const std::string_view& messageArg : messageArgs)
+    {
+        std::string argStr = "%" + std::to_string(i + 1);
+        size_t argPos = msg.find(argStr);
+        if (argPos != std::string::npos)
+        {
+            msg.replace(argPos, argStr.length(), messageArg);
+        }
+        i++;
+    }
+}
+
 } // namespace redfish::message_registries