net/ToString: use libfmt

This commit is contained in:
Max Kellermann 2023-09-18 21:58:37 +02:00
parent 61c29473d3
commit 9398599816

View File

@ -6,6 +6,8 @@
#include "SocketAddress.hxx" #include "SocketAddress.hxx"
#include "IPv4Address.hxx" #include "IPv4Address.hxx"
#include <fmt/core.h>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
@ -75,18 +77,11 @@ ToString(SocketAddress address) noexcept
if (serv[0] != 0 && (serv[0] != '0' || serv[1] != 0)) { if (serv[0] != 0 && (serv[0] != '0' || serv[1] != 0)) {
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
if (std::strchr(host, ':') != nullptr) { if (std::strchr(host, ':') != nullptr) {
std::string result("["); return fmt::format("[{}]:{}", host, serv);
result.append(host);
result.append("]:");
result.append(serv);
return result;
} }
#endif #endif
std::string result(host); return fmt::format("{}:{}", host, serv);
result.push_back(':');
result.append(serv);
return result;
} }
return host; return host;