std.socket: Refactor all *Address.toString implementations to a single base one

This commit is contained in:
Vladimir Panteleev 2011-09-06 20:46:30 +03:00
parent ad2d04668a
commit 65c7f6b80f

View file

@ -1002,9 +1002,6 @@ abstract class Address
/// Returns actual size of underlying $(D sockaddr) structure.
int nameLen() const;
/// Human readable string representing this address.
override string toString() const;
/// Family of this address.
AddressFamily addressFamily() const
{
@ -1109,6 +1106,22 @@ abstract class Address
{
return toServiceString(false);
}
/// Human readable string representing this address.
override string toString() const
{
try
{
string host = toAddrString();
string port = toPortString();
if (host.indexOf(':') >= 0)
return "[" ~ host ~ "]:" ~ port;
else
return host ~ ":" ~ port;
}
catch (SocketException)
return "Unknown";
}
}
/**
@ -1137,11 +1150,6 @@ public:
return sa.sizeof;
}
override string toString() const
{
return "Unknown";
}
}
@ -1185,12 +1193,6 @@ public:
{
return len;
}
override string toString() const
{
return "Unknown";
}
}
@ -1326,12 +1328,6 @@ public:
}
}
/// Human readable string representing the IPv4 address and port in the form $(I a.b.c.d:e).
override string toString() const
{
return toAddrString() ~ ":" ~ toPortString();
}
/**
* Parse an IPv4 address string in the dotted-decimal form $(I a.b.c.d)
* and return the number.
@ -1486,12 +1482,6 @@ public:
sin6.sin6_port = htons(port);
}
/// Human readable string representing the IPv6 address and port.
override string toString() const
{
return "[" ~ toAddrString() ~ "]:" ~ toPortString();
}
/**
* Parse an IPv6 address string as described in RFC 2373, and return the
* address.