Consolidate regex calls when converting links
We currently use multiple regex calls to convert specific
fields to links. Rather than continuing to add new regex
calls for individual link types, we can use one regex to
convert all '/redfish/' paths to links.
Tested:
Checked that all provided redfish paths are converted to
links: odata.id, odata.context, nextLink, Uri, etc.
Change-Id: I2f06e2d5ee9b3d88141f1629f168b3667669d93f
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/http/utility.h b/http/utility.h
index ee88e5a..c71187d 100644
--- a/http/utility.h
+++ b/http/utility.h
@@ -738,18 +738,11 @@
inline void convertToLinks(std::string& s)
{
- const static std::regex r{"("@odata\\.((id)|(Context))"[ \\n]*:[ "
- "\\n]*)("((?!").*)")"};
- s = std::regex_replace(s, r, "$1<a href=\"$6\">$5</a>");
-
- const static std::regex nextLink{
- "("Members@odata\\.((nextLink))"[ \\n]*:[ "
- "\\n]*)("((?!").*)")"};
- s = std::regex_replace(s, nextLink, "$1<a href=\"$5\">$4</a>");
-
- const static std::regex uri{"("((Uri))"[ \\n]*:[ "
- "\\n]*)("((?!").*)")"};
- s = std::regex_replace(s, uri, "$1<a href=\"$5\">$4</a>");
+ // Convert anything with a redfish path into a link
+ const static std::regex redfishPath{
+ "("((.*))"[ \\n]*:[ "
+ "\\n]*)("((?!")/redfish/.*)")"};
+ s = std::regex_replace(s, redfishPath, "$1<a href=\"$5\">$4</a>");
}
/**