1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
template <typename Iterator>
bool parse_line(Iterator first, Iterator last, std::string& s, int& i1, int& i2, int& i3)
{
using namespace boost::spirit;
namespace phx = boost::phoenix;
bool r = qi::phrase_parse(first, last,
(
(
qi::lexeme[+(qi::char_ - ' ') [phx::ref(s) += qi::_1]] >>
qi::int_[phx::ref(i1) = qi::_1] >>
qi::int_[phx::ref(i2) = qi::_1] >>
qi::int_[phx::ref(i3) = qi::_1]
)
), ascii::blank);
if(!r || first != last) return false;
return r;
}
void f()
{
std::string input = "C_1 10 14 12";
std::string o;
int i1, i2, i3;
bool r = parse_line(input.begin(), input.end(), o, i1, i2, i3);
// si r == true alors o == "C_1" && i1 == 10 && i2 == 14 && i3 == 12
} |
Partager