Network/IpAddress: Add a parameter to exclude port from string

This commit is contained in:
SirLynix 2023-12-30 11:14:29 +01:00
parent 8e6ca9cb27
commit 69efb93671
2 changed files with 5 additions and 6 deletions

View File

@ -49,7 +49,7 @@ namespace Nz
inline IPv4 ToIPv4() const; inline IPv4 ToIPv4() const;
inline IPv6 ToIPv6() const; inline IPv6 ToIPv6() const;
std::string ToString() const; std::string ToString(bool includesPort = true) const;
inline UInt32 ToUInt32() const; inline UInt32 ToUInt32() const;
inline explicit operator bool() const; inline explicit operator bool() const;

View File

@ -104,8 +104,7 @@ namespace Nz
* *
* \remark Produces a NazaraAssert if internal protocol is invalid (should never happen) * \remark Produces a NazaraAssert if internal protocol is invalid (should never happen)
*/ */
std::string IpAddress::ToString(bool includesPort) const
std::string IpAddress::ToString() const
{ {
std::ostringstream stream; std::ostringstream stream;
@ -155,7 +154,7 @@ namespace Nz
} }
// We need brackets around our IPv6 address if we have a port // We need brackets around our IPv6 address if we have a port
if (m_port != 0) if (m_port != 0 && includesPort)
stream << '['; stream << '[';
// IPv4-mapped IPv6? // IPv4-mapped IPv6?
@ -195,12 +194,12 @@ namespace Nz
} }
if (m_port != 0) if (m_port != 0 && includesPort)
stream << ']'; stream << ']';
break; break;
} }
if (m_port != 0) if (m_port != 0 && includesPort)
stream << ':' << m_port; stream << ':' << m_port;
} }