home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,341 of 33,346   
   Mark to All   
   boost::spirit   
   26 May 14 07:28:46   
   
   From: ma740988@googlemail.com   
      
   { text (not code) has been formatted to make lines ~70 chars. -mod }   
      
   Consider   
      
   # include    
   # include    
   # include    
   # include    
      
   # include    
   # include    
   # include    
   # include    
   # include    
   # include    
   # include    
   # include    
   # include    
   # include    
      
      
   int main( ) {   
      
     std::string text   
         ( "time=10.000,21.000&checksum=100,200&uLeftLat=20.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! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca