Fix space-matches 0 spaces at end of format string

This commit is contained in:
Howard Hinnant
2019-08-23 15:48:41 -04:00
parent dca8ddc659
commit 141ba85614

View File

@@ -6347,7 +6347,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
using detail::ru; using detail::ru;
using detail::rld; using detail::rld;
using detail::checked_set; using detail::checked_set;
for (; *fmt && is.rdstate() == std::ios::goodbit; ++fmt) for (; *fmt != CharT{} && !is.fail(); ++fmt)
{ {
switch (*fmt) switch (*fmt)
{ {
@@ -7348,14 +7348,18 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
else // !command else // !command
{ {
if (isspace(static_cast<unsigned char>(*fmt))) if (isspace(static_cast<unsigned char>(*fmt)))
ws(is); // space matches 0 or more white space characters {
// space matches 0 or more white space characters
if (is.good())
ws(is);
}
else else
read(is, *fmt); read(is, *fmt);
} }
break; break;
} }
} }
// is.rdstate() != ios::goodbit || *fmt == CharT{} // is.fail() || *fmt == CharT{}
if (is.rdstate() == ios::goodbit && command) if (is.rdstate() == ios::goodbit && command)
{ {
if (modified == CharT{}) if (modified == CharT{})
@@ -7363,8 +7367,6 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
else else
read(is, CharT{'%'}, width, modified); read(is, CharT{'%'}, width, modified);
} }
if (is.rdstate() != ios::goodbit && *fmt != CharT{} && !is.fail())
is.setstate(ios::failbit);
if (!is.fail()) if (!is.fail())
{ {
if (y != not_a_2digit_year) if (y != not_a_2digit_year)