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/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