Handle whitespace separating an 'ip port' correctly (RIPD-552)

This commit is contained in:
Nik Bougalis
2014-09-02 17:37:25 -07:00
committed by Vinnie Falco
parent a3fe089367
commit 624a803955
4 changed files with 785 additions and 771 deletions

View File

@@ -42,6 +42,20 @@ bool expect (InputStream& is, char v)
return false;
}
/** Require and consume whitespace from the input.
@return `true` if the character matched.
*/
template <typename InputStream>
bool expect_whitespace (InputStream& is)
{
char c;
if (is.get(c) && isspace(c))
return true;
is.unget();
is.setstate (std::ios_base::failbit);
return false;
}
/** Used to disambiguate 8-bit integers from characters. */
template <typename IntType>
struct integer_holder

View File

@@ -79,14 +79,14 @@ Endpoint Endpoint::from_string_altform (std::string const& s)
if (is.rdbuf()->in_avail()>0)
{
if (! IP::detail::expect (is, ' '))
if (! IP::detail::expect_whitespace (is))
return Endpoint();
while (is.rdbuf()->in_avail()>0)
{
char c;
is.get(c);
if (c != ' ')
if (!isspace (c))
{
is.unget();
break;