Replace boost starts_with with std::string
C++20 introduces std::string::starts_with, which provides standard,
efficient, and header-light ways to check string prefixes and
suffixes.
Replacing boost::starts_with reduces Boost dependencies, and improves
compilation performance.
Change-Id: I5f146d9a1abe6d04d95f8228853139eda773218c
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/src/entity_manager/entity_manager.cpp b/src/entity_manager/entity_manager.cpp
index d66695f..4623141 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -16,7 +16,6 @@
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/asio/io_context.hpp>
diff --git a/src/entity_manager/overlay.cpp b/src/entity_manager/overlay.cpp
index 64c11ed..635a5b8 100644
--- a/src/entity_manager/overlay.cpp
+++ b/src/entity_manager/overlay.cpp
@@ -6,7 +6,6 @@
#include "devices.hpp"
#include "utils.hpp"
-#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
diff --git a/src/entity_manager/perform_scan.cpp b/src/entity_manager/perform_scan.cpp
index 35430d8..c71fa48 100644
--- a/src/entity_manager/perform_scan.cpp
+++ b/src/entity_manager/perform_scan.cpp
@@ -6,7 +6,6 @@
#include "perform_probe.hpp"
#include "utils.hpp"
-#include <boost/algorithm/string/predicate.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
@@ -84,7 +83,7 @@
// Introspectable, and Properties) are returned by
// the mapper but don't have properties, so don't bother
// with the GetAll call to save some cycles.
- if (!boost::algorithm::starts_with(iface, "org.freedesktop"))
+ if (!iface.starts_with("org.freedesktop"))
{
getInterfaces({busname, path, iface}, probeVector, scan,
io);
@@ -292,7 +291,7 @@
nlohmann::json& expose,
const std::string& propertyName)
{
- if (boost::starts_with(propertyName, "Bind"))
+ if (propertyName.starts_with("Bind"))
{
std::string bind = propertyName.substr(sizeof("Bind") - 1);
exposedObject["Status"] = "okay";
@@ -329,7 +328,7 @@
nlohmann::json& systemConfiguration, const std::string& recordName,
nlohmann::json& expose, nlohmann::json::iterator& keyPair)
{
- bool isBind = boost::starts_with(keyPair.key(), "Bind");
+ bool isBind = keyPair.key().starts_with("Bind");
bool isDisable = keyPair.key() == "DisableNode";
bool isExposeAction = isBind || isDisable;
diff --git a/src/entity_manager/utils.cpp b/src/entity_manager/utils.cpp
index 8af3dce..3e4a805 100644
--- a/src/entity_manager/utils.cpp
+++ b/src/entity_manager/utils.cpp
@@ -6,7 +6,6 @@
#include <boost/algorithm/string/case_conv.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/algorithm/string/split.hpp>
#include <sdbusplus/bus/match.hpp>
@@ -205,7 +204,7 @@
std::string_view strView = *strPtr;
int base = 10;
- if (boost::starts_with(strView, "0x"))
+ if (strView.starts_with("0x"))
{
strView.remove_prefix(2);
base = 16;
diff --git a/src/fru_device/fru_device.cpp b/src/fru_device/fru_device.cpp
index f45766c..9b13a2c 100644
--- a/src/fru_device/fru_device.cpp
+++ b/src/fru_device/fru_device.cpp
@@ -8,7 +8,6 @@
#include <sys/inotify.h>
#include <sys/ioctl.h>
-#include <boost/algorithm/string/predicate.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
@@ -1475,7 +1474,7 @@
case IN_DELETE:
{
std::string_view name(&iEvent->name[0], iEvent->len);
- if (boost::starts_with(name, "i2c"))
+ if (name.starts_with("i2c"))
{
int bus = busStrToInt(name);
if (bus < 0)
diff --git a/src/utils.cpp b/src/utils.cpp
index f0e8d25..b408aea 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -5,7 +5,6 @@
#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/algorithm/string/split.hpp>
#include <boost/container/flat_map.hpp>