I'm trying to parse a simple text file using boost::spirit. The text file is a line delimited list of strings. I can get it to mostly work, except for when it comes to blank lines, which I would like to skip.
I've tried several approaches, but I either stop parsing at the blank line, or I get the blank line included in my results.
Is there a way to tell my grammar to skip blank lines?
code
std::ifstream ifs("one.txt");
ifs >> std::noskipws;
std::vector< std::string > people;
if (parse(
istream_iterator(ifs),
istream_iterator(),
*(as_string[+print >> (eol | eoi)]),
people))
{
std::cout << "Size = " << people.size() << std::endl;
for (auto person : people)
{
std::cout << person << std::endl;
}
}
one.txt
Sally
Joe
Frank
Mary Ann
Bob
What I Get
Sally
Joe
Frank
Mary Ann
What I Want to Get
Sally
Joe
Frank
Mary Ann
Bob
Bonus: Can I strip leading or trailing spaces from the lines in the grammar at the same time? I need to keep the space in Mary Ann of course.