treewide: Convert most fmt::format -> std::format
Change-Id: I3c9ac1eed1c86c6cd9f7fd3a1ba356734e79f937
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/config_parser.cpp b/src/config_parser.cpp
index 8c84e95..e73c889 100644
--- a/src/config_parser.cpp
+++ b/src/config_parser.cpp
@@ -1,7 +1,5 @@
#include "config_parser.hpp"
-#include <fmt/format.h>
-
#include <stdplus/exception.hpp>
#include <stdplus/fd/atomic.hpp>
#include <stdplus/fd/create.hpp>
@@ -9,6 +7,7 @@
#include <stdplus/fd/line.hpp>
#include <stdplus/str/cat.hpp>
+#include <format>
#include <functional>
#include <iterator>
#include <stdexcept>
@@ -164,7 +163,7 @@
auto cpos = line.find(']');
if (cpos == line.npos)
{
- warnings.emplace_back(fmt::format("{}:{}: Section missing ]",
+ warnings.emplace_back(std::format("{}:{}: Section missing ]",
filename.get().native(), lineno));
}
else
@@ -174,7 +173,7 @@
if (!isspace(c))
{
warnings.emplace_back(
- fmt::format("{}:{}: Characters outside section name",
+ std::format("{}:{}: Characters outside section name",
filename.get().native(), lineno));
break;
}
@@ -196,7 +195,7 @@
std::vector<std::string> new_warnings;
if (epos == line.npos)
{
- new_warnings.emplace_back(fmt::format(
+ new_warnings.emplace_back(std::format(
"{}:{}: KV missing `=`", filename.get().native(), lineno));
}
auto k = line.substr(0, epos);
@@ -204,7 +203,7 @@
if (section == nullptr)
{
new_warnings.emplace_back(
- fmt::format("{}:{}: Key `{}` missing section",
+ std::format("{}:{}: Key `{}` missing section",
filename.get().native(), lineno, k));
}
if (!new_warnings.empty())
@@ -270,7 +269,7 @@
fileExists = false;
// TODO: Pass exceptions once callers can handle them
parse.warnings.emplace_back(
- fmt::format("{}: Open error: {}", filename.native(), e.what()));
+ std::format("{}: Open error: {}", filename.native(), e.what()));
}
this->map = std::move(parse.map);
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 11485b9..fdd01c2 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -6,7 +6,6 @@
#include "system_queries.hpp"
#include "util.hpp"
-#include <fmt/format.h>
#include <linux/rtnetlink.h>
#include <net/if.h>
#include <net/if_arp.h>
@@ -20,6 +19,7 @@
#include <algorithm>
#include <filesystem>
+#include <format>
#include <string>
#include <unordered_map>
#include <variant>
@@ -527,7 +527,7 @@
ServerList EthernetInterface::getNameServerFromResolvd()
{
ServerList servers;
- auto OBJ_PATH = fmt::format("{}{}", RESOLVED_SERVICE_PATH, ifIdx);
+ auto OBJ_PATH = std::format("{}{}", RESOLVED_SERVICE_PATH, ifIdx);
/*
The DNS property under org.freedesktop.resolve1.Link interface contains
@@ -704,9 +704,7 @@
{
if (originIsManuallyAssigned(addr.second->origin()))
{
- address.emplace_back(
- fmt::format("{}/{}", addr.second->address(),
- addr.second->prefixLength()));
+ address.emplace_back(stdplus::toStr(addr.first));
}
}
}
diff --git a/src/netlink.cpp b/src/netlink.cpp
index 69ea5c6..eccf039 100644
--- a/src/netlink.cpp
+++ b/src/netlink.cpp
@@ -1,6 +1,5 @@
#include "netlink.hpp"
-#include <fmt/format.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
@@ -9,6 +8,7 @@
#include <stdplus/raw.hpp>
#include <array>
+#include <format>
#include <stdexcept>
#include <system_error>
@@ -30,13 +30,13 @@
if (hdr.nlmsg_len < sizeof(hdr))
{
throw std::runtime_error(
- fmt::format("nlmsg length shorter than header: {} < {}",
+ std::format("nlmsg length shorter than header: {} < {}",
hdr.nlmsg_len, sizeof(hdr)));
}
if (msgs.size() < hdr.nlmsg_len)
{
throw std::runtime_error(
- fmt::format("not enough message for nlmsg: {} < {}", msgs.size(),
+ std::format("not enough message for nlmsg: {} < {}", msgs.size(),
hdr.nlmsg_len));
}
auto msg = msgs.substr(NLMSG_HDRLEN, hdr.nlmsg_len - NLMSG_HDRLEN);
@@ -185,13 +185,13 @@
const auto& hdr = stdplus::raw::refFrom<rtattr, Aligned>(data);
if (hdr.rta_len < RTA_LENGTH(0))
{
- throw std::runtime_error(fmt::format(
+ throw std::runtime_error(std::format(
"rtattr shorter than header: {} < {}", hdr.rta_len, RTA_LENGTH(0)));
}
if (data.size() < hdr.rta_len)
{
throw std::runtime_error(
- fmt::format("not enough message for rtattr: {} < {}", data.size(),
+ std::format("not enough message for rtattr: {} < {}", data.size(),
hdr.rta_len));
}
auto attr = data.substr(RTA_LENGTH(0), hdr.rta_len - RTA_LENGTH(0));
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index b14c106..47a528f 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -17,9 +17,11 @@
#include <stdplus/numeric/str.hpp>
#include <stdplus/pinned.hpp>
#include <stdplus/print.hpp>
+#include <stdplus/str/cat.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <filesystem>
+#include <format>
namespace phosphor
{
@@ -29,6 +31,7 @@
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using Argument = xyz::openbmc_project::Common::InvalidArgument;
+using std::literals::string_view_literals::operator""sv;
static constexpr const char enabledMatch[] =
"type='signal',sender='org.freedesktop.network1',path_namespace='/org/"
@@ -134,7 +137,9 @@
for (const auto& link : links)
{
unsigned ifidx = std::get<0>(link);
- auto obj = fmt::format("/org/freedesktop/network1/link/_3{}", ifidx);
+ stdplus::ToStrHandle<stdplus::IntToStr<10, unsigned>> tsh;
+ auto obj = stdplus::strCat("/org/freedesktop/network1/link/_3"sv,
+ tsh(ifidx));
auto req =
bus.get().new_method_call("org.freedesktop.network1", obj.c_str(),
"org.freedesktop.DBus.Properties", "Get");
@@ -297,7 +302,7 @@
else if (!ignoredIntf.contains(info.ifidx))
{
throw std::runtime_error(
- fmt::format("Interface `{}` not found for addr", info.ifidx));
+ std::format("Interface `{}` not found for addr", info.ifidx));
}
}
@@ -331,7 +336,7 @@
else if (!ignoredIntf.contains(info.ifidx))
{
throw std::runtime_error(
- fmt::format("Interface `{}` not found for neigh", info.ifidx));
+ std::format("Interface `{}` not found for neigh", info.ifidx));
}
}
diff --git a/src/system_queries.cpp b/src/system_queries.cpp
index f58493a..17dd09a 100644
--- a/src/system_queries.cpp
+++ b/src/system_queries.cpp
@@ -2,7 +2,6 @@
#include "netlink.hpp"
-#include <fmt/format.h>
#include <linux/ethtool.h>
#include <linux/rtnetlink.h>
#include <linux/sockios.h>
@@ -14,6 +13,7 @@
#include <stdplus/util/cexec.hpp>
#include <algorithm>
+#include <format>
#include <optional>
#include <stdexcept>
#include <string_view>
@@ -126,7 +126,7 @@
err = netlink::extractRtData<nlmsgerr>(data).error;
}
throw std::runtime_error(
- fmt::format("Failed to delete `{}`: {}", idx, strerror(err)));
+ std::format("Failed to delete `{}`: {}", idx, strerror(err)));
});
}