Created
April 18, 2016 16:06
-
-
Save jefftrull/0d7ecfef151c39885a7633d7547df8e6 to your computer and use it in GitHub Desktop.
*qi::string is compatible with both std::string (concatenation) and std::vector<std::string> (push_back) attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <boost/spirit/include/qi.hpp> | |
using string_it_t = std::string::const_iterator; | |
int main() { | |
using namespace boost::spirit; | |
using namespace boost::spirit::qi; | |
rule<string_it_t, std::string()> r; | |
rule<string_it_t, std::vector<std::string>()> r2; | |
r = +qi::string("foo") ; | |
r2 = +qi::string("foo") ; | |
std::string testcase("foofoofoofoo"); | |
std::string result; | |
auto beg = testcase.cbegin(); | |
parse(beg, testcase.cend(), r, result); | |
std::cout << "result: " << result << "\n"; | |
std::vector<std::string> result2; | |
beg = testcase.cbegin(); | |
parse(beg, testcase.cend(), r2, result2); | |
std::cout << "result2:\n"; | |
for( auto const& s : result2 ) { | |
std::cout << s << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment