Boost::urls::format

Boost 1.82 dropped a lovely new toy, boost::urls::format, which is a lot
like our urlFromPieces method, but better in that it makes the resulting
uris more readable, and allows doing things like fragments in a single
line instead of multiple.  We should prefer it in some cases.

Tested:
Redfish service validator passes.
Spot checks of URLs work as expected.
Unit tests pass.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia7b38f0a95771c862507e7d5b4aa68aa1c98403c
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 819a788..eb453f2 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -28,6 +28,7 @@
 #include "utils/time_utils.hpp"
 
 #include <boost/system/error_code.hpp>
+#include <boost/url/format.hpp>
 #include <sdbusplus/asio/property.hpp>
 #include <sdbusplus/unpack_properties.hpp>
 
@@ -392,8 +393,7 @@
                     }
                 }
 
-                boost::urls::url url = crow::utility::urlFromPieces(
-                    "redfish", "v1", "Managers", "bmc");
+                boost::urls::url url("/redfish/v1/Managers/bmc");
                 if (intfPair.first == pidZoneConfigurationIface)
                 {
                     std::string chassis;
@@ -403,8 +403,8 @@
                         chassis = "#IllegalValue";
                     }
                     nlohmann::json& zone = zones[name];
-                    zone["Chassis"]["@odata.id"] = crow::utility::urlFromPieces(
-                        "redfish", "v1", "Chassis", chassis);
+                    zone["Chassis"]["@odata.id"] =
+                        boost::urls::format("/redfish/v1/Chassis/{}", chassis);
                     url.set_fragment(
                         ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / name)
                             .to_string());
@@ -584,10 +584,8 @@
                             {
                                 dbus::utility::escapePathForDbus(itemCopy);
                                 nlohmann::json::object_t input;
-                                boost::urls::url managerUrl =
-                                    crow::utility::urlFromPieces(
-                                        "redfish", "v1", "Managers", "bmc");
-                                managerUrl.set_fragment(
+                                boost::urls::url managerUrl = boost::urls::format(
+                                    "/redfish/v1/Managers/bmc#{}",
                                     ("/Oem/OpenBmc/Fan/FanZones"_json_pointer /
                                      itemCopy)
                                         .to_string());
@@ -826,9 +824,9 @@
         if (managedItem == nullptr)
         {
             BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
-            messages::invalidObject(response->res,
-                                    crow::utility::urlFromPieces(
-                                        "redfish", "v1", "Chassis", chassis));
+            messages::invalidObject(
+                response->res,
+                boost::urls::format("/redfish/v1/Chassis/{}", chassis));
             return CreatePIDRet::fail;
         }
     }
@@ -939,8 +937,8 @@
             {
                 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
                 messages::invalidObject(
-                    response->res, crow::utility::urlFromPieces(
-                                       "redfish", "v1", "Chassis", chassis));
+                    response->res,
+                    boost::urls::format("/redfish/v1/Chassis/{}", chassis));
                 return CreatePIDRet::fail;
             }
             output.emplace_back("Zones", std::move(zonesStr));
@@ -1034,8 +1032,8 @@
             {
                 BMCWEB_LOG_ERROR << "Got invalid path " << chassisId;
                 messages::invalidObject(
-                    response->res, crow::utility::urlFromPieces(
-                                       "redfish", "v1", "Chassis", chassisId));
+                    response->res,
+                    boost::urls::format("/redfish/v1/Chassis/{}", chassisId));
                 return CreatePIDRet::fail;
             }
         }
@@ -1080,8 +1078,8 @@
             {
                 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
                 messages::invalidObject(
-                    response->res, crow::utility::urlFromPieces(
-                                       "redfish", "v1", "Chassis", chassis));
+                    response->res,
+                    boost::urls::format("/redfish/v1/Chassis/{}", chassis));
                 return CreatePIDRet::fail;
             }
             output.emplace_back("Zones", std::move(zonesStrs));
@@ -1643,8 +1641,8 @@
                         BMCWEB_LOG_ERROR << "Failed to find chassis on dbus";
                         messages::resourceMissingAtURI(
                             response->res,
-                            crow::utility::urlFromPieces("redfish", "v1",
-                                                         "Chassis", chassis));
+                            boost::urls::format("/redfish/v1/Chassis/{}",
+                                                chassis));
                         return;
                     }
 
@@ -2023,8 +2021,8 @@
             aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1;
             nlohmann::json::array_t managerForChassis;
             nlohmann::json::object_t managerObj;
-            boost::urls::url chassiUrl = crow::utility::urlFromPieces(
-                "redfish", "v1", "Chassis", chassisId);
+            boost::urls::url chassiUrl =
+                boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
             managerObj["@odata.id"] = chassiUrl;
             managerForChassis.emplace_back(std::move(managerObj));
             aRsp->res.jsonValue["Links"]["ManagerForChassis"] =