Remove some boost includes
The less we rely on boost, and more on std algorithms, the less people
have to look up, and the more likely that our code will deduplicate.
Replace all uses of boost::algorithms with std alternatives.
Tested: Redfish Service Validator passes.
Change-Id: I8a26f39b5709adc444b4178e92f5f3c7b988b05b
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 19e32ce..1935adc 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -26,11 +26,6 @@
#include "utils/json_utils.hpp"
#include "utils/query_param.hpp"
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/find.hpp>
-#include <boost/algorithm/string/predicate.hpp>
-#include <boost/algorithm/string/replace.hpp>
-#include <boost/range/algorithm/replace_copy_if.hpp>
#include <boost/system/error_code.hpp>
#include <boost/url/format.hpp>
#include <sdbusplus/asio/property.hpp>
@@ -43,6 +38,7 @@
#include <map>
#include <ranges>
#include <set>
+#include <string>
#include <string_view>
#include <utility>
#include <variant>
@@ -823,7 +819,10 @@
}
else if (sensorType == "power")
{
- if (boost::iequals(sensorName, "total_power"))
+ std::string lower;
+ std::ranges::transform(sensorName, std::back_inserter(lower),
+ bmcweb::asciiToLower);
+ if (lower == "total_power")
{
sensorJson["@odata.type"] = "#Power.v1_0_0.PowerControl";
// Put multiple "sensors" into a single PowerControl, so have
@@ -832,7 +831,7 @@
sensorJson["Name"] = "Chassis Power Control";
unit = "/PowerConsumedWatts"_json_pointer;
}
- else if (!(boost::ifind_first(sensorName, "input").empty()))
+ else if (lower.find("input") != std::string::npos)
{
unit = "/PowerInputWatts"_json_pointer;
}
@@ -1073,7 +1072,7 @@
sensorsAsyncResp->asyncResp->res);
return;
}
- std::replace(name.begin(), name.end(), '_', ' ');
+ std::ranges::replace(name, '_', ' ');
std::string health;
@@ -2186,11 +2185,22 @@
const InventoryItem& inventoryItem,
const std::string& chassisId)
{
+ std::string nameS;
+ std::ranges::replace_copy(inventoryItem.name, nameS.begin(), '_', ' ');
// Check if matching PowerSupply object already exists in JSON array
for (nlohmann::json& powerSupply : powerSupplyArray)
{
- if (powerSupply["Name"] ==
- boost::replace_all_copy(inventoryItem.name, "_", " "))
+ nlohmann::json::iterator nameIt = powerSupply.find("Name");
+ if (nameIt == powerSupply.end())
+ {
+ continue;
+ }
+ const std::string* name = nameIt->get_ptr<std::string*>();
+ if (name == nullptr)
+ {
+ continue;
+ }
+ if (nameS == *name)
{
return powerSupply;
}
@@ -2203,7 +2213,9 @@
chassisId);
url.set_fragment(("/PowerSupplies"_json_pointer).to_string());
powerSupply["@odata.id"] = std::move(url);
- powerSupply["Name"] = boost::replace_all_copy(inventoryItem.name, "_", " ");
+ std::string escaped;
+ std::ranges::replace_copy(inventoryItem.name, escaped.begin(), '_', ' ');
+ powerSupply["Name"] = std::move(escaped);
powerSupply["Manufacturer"] = inventoryItem.manufacturer;
powerSupply["Model"] = inventoryItem.model;
powerSupply["PartNumber"] = inventoryItem.partNumber;