From 69efb93671f4fcd9d80043aee3440e348dd24dfb Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sat, 30 Dec 2023 11:14:29 +0100 Subject: [PATCH] Network/IpAddress: Add a parameter to exclude port from string --- include/Nazara/Network/IpAddress.hpp | 2 +- src/Nazara/Network/IpAddress.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/Nazara/Network/IpAddress.hpp b/include/Nazara/Network/IpAddress.hpp index c4189b2e2..a5679a4bc 100644 --- a/include/Nazara/Network/IpAddress.hpp +++ b/include/Nazara/Network/IpAddress.hpp @@ -49,7 +49,7 @@ namespace Nz inline IPv4 ToIPv4() const; inline IPv6 ToIPv6() const; - std::string ToString() const; + std::string ToString(bool includesPort = true) const; inline UInt32 ToUInt32() const; inline explicit operator bool() const; diff --git a/src/Nazara/Network/IpAddress.cpp b/src/Nazara/Network/IpAddress.cpp index d38f2973b..fd215559e 100644 --- a/src/Nazara/Network/IpAddress.cpp +++ b/src/Nazara/Network/IpAddress.cpp @@ -104,8 +104,7 @@ namespace Nz * * \remark Produces a NazaraAssert if internal protocol is invalid (should never happen) */ - - std::string IpAddress::ToString() const + std::string IpAddress::ToString(bool includesPort) const { std::ostringstream stream; @@ -155,7 +154,7 @@ namespace Nz } // We need brackets around our IPv6 address if we have a port - if (m_port != 0) + if (m_port != 0 && includesPort) stream << '['; // IPv4-mapped IPv6? @@ -195,12 +194,12 @@ namespace Nz } - if (m_port != 0) + if (m_port != 0 && includesPort) stream << ']'; break; } - if (m_port != 0) + if (m_port != 0 && includesPort) stream << ':' << m_port; }