2
0
mirror of https://github.com/boostorg/spirit.git synced 2026-01-19 04:42:11 +00:00

ts_real_policies: Fixed small numbers parsing

Numbers in range (-1000.0, 1000.0) has only one segment (no thousands delimiter),
and are parsed in `if` statement expression.
This commit is contained in:
Nikita Kniazev
2018-03-10 18:52:50 +03:00
parent a0df3c098f
commit 1a72c27306
5 changed files with 14 additions and 15 deletions

View File

@@ -168,7 +168,6 @@ struct ts_real_policies : boost::spirit::qi::ureal_policies<T>
T result = 0;
if (parse(first, last, uint3, result))
{
bool hit = false;
T n;
Iterator save = first;
@@ -176,13 +175,11 @@ struct ts_real_policies : boost::spirit::qi::ureal_policies<T>
{
result = result * 1000 + n;
save = first;
hit = true;
}
first = save;
if (hit)
attr = result;
return hit;
attr = result;
return true;
}
return false;
}

View File

@@ -71,7 +71,6 @@ struct ts_real_policies : boost::spirit::qi::ureal_policies<T>
acc_type result = 0;
if (parse(first, last, uint3, result))
{
bool hit = false;
acc_type n;
Iterator save = first;
@@ -79,13 +78,11 @@ struct ts_real_policies : boost::spirit::qi::ureal_policies<T>
{
result = result * 1000 + n;
save = first;
hit = true;
}
first = save;
if (hit)
attr = result;
return hit;
attr = result;
return true;
}
return false;
}

View File

@@ -59,6 +59,10 @@ main()
real_parser<double, ts_real_policies<double> > ts_real;
double d;
BOOST_TEST(test("123.01", ts_real));
BOOST_TEST(test_attr("123.01", ts_real, d)
&& compare(d, 123.01));
BOOST_TEST(test("123,456,789.01", ts_real));
BOOST_TEST(test_attr("123,456,789.01", ts_real, d)
&& compare(d, 123456789.01));

View File

@@ -67,7 +67,6 @@ struct ts_real_policies : boost::spirit::x3::ureal_policies<T>
T result = 0;
if (parse(first, last, uint3, result))
{
bool hit = false;
T n;
Iterator save = first;
@@ -75,13 +74,11 @@ struct ts_real_policies : boost::spirit::x3::ureal_policies<T>
{
result = result * 1000 + n;
save = first;
hit = true;
}
first = save;
if (hit)
attr = result;
return hit;
attr = result;
return true;
}
return false;
}

View File

@@ -59,6 +59,10 @@ main()
real_parser<double, ts_real_policies<double> > ts_real;
double d;
BOOST_TEST(test("123.01", ts_real));
BOOST_TEST(test_attr("123.01", ts_real, d)
&& compare(d, 123.01));
BOOST_TEST(test("123,456,789.01", ts_real));
BOOST_TEST(test_attr("123,456,789.01", ts_real, d)
&& compare(d, 123456789.01));