Qi ushort_?
Michael Powell <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CAMEoF_EEtJEGgK56wnQC-3a4oRcGgUwv3zfRTJJwZaMDceMm2Q@mail.gmail.com> |
Hello,
What is this, exactly? I'm not sure I fully understand from the
documentation, and the parameters _0_, _1_, etc, aren't very
descriptive.
http://www.boost.org/doc/libs/1_65_1/libs/spirit/doc/html/spirit/qi/reference/numeric/uint.html
Am I specifying either a precise value? Or the range? Is the default
the full range? i.e.
using namespace std;
using namespace boost::spirit::qi;
// ...
ushort_ // same as saying...
ushort_(numeric_limits<uint16_t>::min(), numeric_limits<uint16_t>::max())
/* or this in case you had to prove it to yourself */ ushort_(0, 65535)
If so, that would be far simpler than taking a more circuitous route.
Just thank goodness port numbers, in this case, aren't 64-bit or even
32-bit unsigned integers.
Further than that, I'm not sure how these unit test assertions prove
exhaustively that this "works". They show alternatives, and that not
exhaustively, either. But not 0-65535, to be clear.
BOOST_TEST(test("123", ushort_(0) | ushort_(123)));
BOOST_TEST(test("123", ushort_(123) | ushort_(0)));
i.e.
_port_rule = (
(char_('0'))
| (char_('1', '5') >> -(digit >> -(digit >> -(digit >> -digit))))
| (char_('6')
>> -((char_('0', '4') >> -(digit >> -(digit >> -digit)))
| (char_('5')
>> -((char_('0', '4') >> -(digit >> -digit))
| (char_('5')
>> -((char_('0', '2') >> -digit)
| (char_('3') >> -char_('0', '5'))
| (char_('4', '9'))
))
| (char_('6', '9') >> -digit)
))
| (char_('6', '9') >> -(digit >> -digit))
)
)
| (char_('7', '9') >> -(digit >> -(digit >> -digit))))
;
Tested across the full range of 0-65535, including absurdly incorrect
use cases, negative numbers, non-digit character strings, floating
point string representations.
Looking at a migration path forward, does the same thing exist for X3?
Cheers,
Michael Powell
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot