boost::spirit
{ text (not code) has been formatted to make lines ~70 chars. -mod }
Consider
# include <iostream>
# include <string>
# include <map>
# include <vector>
# include <boost/random/random_device.hpp>
# include <boost/random/uniform_int_distribution.hpp>
# include <boost/foreach.hpp>
# include <boost/tokenizer.hpp>
# include <boost/algorithm/string.hpp>
# include <boost/spirit/include/qi.hpp>
# include <boost/spirit/include/karma.hpp>
# include <boost/fusion/adapted/std_pair.hpp>
# include <boost/random/mersenne_twister.hpp>
# include <boost/random/uniform_int_distribution.hpp>
int main( ) {
std::string text
( "time=10.000,21.000&checksum=100,200&uLeftLat .000,\
uLeftLon=21.000,bRightLat=21.00,bRightLon=22.000&mid=Blue Rain");
using namespace boost::spirit ;
typedef std::map < std::string, std::string > STR_MAP ;
STR_MAP contents;
std::string::iterator first = text.begin() ;
std::string::iterator last = text.end() ;
const bool result = qi::phrase_parse
( first, last,
*( * ( qi::char_-"=") >> qi::lit ( "=") >>
* ( qi::char_-"," ) >> -qi::lit(",") ) , ascii::space, contents ) ;
std::cout << " result = " << result << ", output Size = " << contents.size() << std::endl;
if ( !result ) {
std::cin.get();
return EXIT_FAILURE ;
}
for ( STR_MAP::iterator it = contents.begin();
it != contents.end(); ++it ){
std::cout << it->first << " " << it->second << std::endl;
}
std::cin.get();
}
The map output currently is as follows:
200&uLeftLat 20.000
21.000&checksum 100
bRightLat 21.00
bRightLon 22.000&mid=BlueRain
time 10.000
uLeftLon 21.000
What I want is this :
time 10.000 21.000
checksum 100 200
uLeftLat 20.000
uLeftLon 21.000
bRightLat 21.00
bRightLon 22.000
mid Blue Rain
Having a hard time filtering on the ampersand. What's the phrase_parse
combination that'll help me achieve the desired output?
NOTE: There's a unique case where the key value pair for timestamp and
checksum might be as follows: key=value1,value2 The end result should
be key value1 value2.
NOTE: checksum and timestamp could also be key=value
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]