Tweak white space parsing rules (again):

* White space matches zero or more white space characters.

  * %n matches one white space character.

  * %t matches zero or one white space characters.
This commit is contained in:
Howard Hinnant
2017-05-07 15:25:07 -04:00
parent cf0481b9af
commit f493bd67f2
2 changed files with 104 additions and 24 deletions
+78
View File
@@ -740,6 +740,81 @@ test_leading_ws()
assert(d2 == may/4/2017);
}
void
test_space()
{
using namespace std;
using namespace date;
{
istringstream in{"05/04/17"};
year_month_day d1;
in >> parse(" %D", d1);
assert(d1 == may/4/2017);
}
{
istringstream in{" 05/04/17"};
year_month_day d1;
in >> parse(" %D", d1);
assert(d1 == may/4/2017);
}
{
istringstream in{" 05/04/17"};
year_month_day d1;
in >> parse(" %D", d1);
assert(d1 == may/4/2017);
}
}
void
test_n()
{
using namespace std;
using namespace date;
{
istringstream in{"05/04/17"};
year_month_day d1;
in >> parse("%n%D", d1);
assert(in.fail());
}
{
istringstream in{" 05/04/17"};
year_month_day d1;
in >> parse("%n%D", d1);
assert(d1 == may/4/2017);
}
{
istringstream in{" 05/04/17"};
year_month_day d1;
in >> parse("%n%D", d1);
assert(in.fail());
}
}
void
test_t()
{
using namespace std;
using namespace date;
{
istringstream in{"05/04/17"};
year_month_day d1;
in >> parse("%t%D", d1);
assert(d1 == may/4/2017);
}
{
istringstream in{" 05/04/17"};
year_month_day d1;
in >> parse("%t%D", d1);
assert(d1 == may/4/2017);
}
{
istringstream in{" 05/04/17"};
year_month_day d1;
in >> parse("%t%D", d1);
assert(in.fail());
}
}
int
main()
{
@@ -769,4 +844,7 @@ main()
test_Z();
test_trailing_Z();
test_leading_ws();
test_space();
test_n();
test_t();
}