Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:43:11+00:00 2026-05-26T15:43:11+00:00

I am trying to parse a noisy input, ideally I would be able to

  • 0

I am trying to parse a noisy input, ideally I would be able to see whether a stanza matchs the rule and if it does get the data I need and discard the rest.

The data I want is as follows.

Event: Newstate
Channel: SIP/104-000001bb
ChannelState: 6
ChannelStateDesc: Up

I want to make sure that Event if of type new state.

And I need the channel state. The rest I don’t care about (just yet) so I want to ignore it, I want it to be flexible and accept any old crap bettween the important stuff, really i don’t want to say ignore this line, but rather ignore anything between Event and the end of channel state where I capture the value.

So far I have got:

typedef boost::fusion::vector2<std::string, std::string> vect;
qi::rule<std::string::iterator, vect(), space> rule_ =
            lit("Event: ")      >> *char_("a-zA-Z") >>  
            qi::omit[ *char_ ]  >>  
            "ChannelState: "    >> *char_("0-9")    >>  
            qi::omit[ *char_ ];

but this isn’t working for some reason, I always get false back when I do this:

vect v;
bool r=qi::parse(it, str.end(), rule_, v); 

EDIT: Boost version 1.42 compiler g++ 4.4 Spirit 0x2020

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:43:12+00:00Added an answer on May 26, 2026 at 3:43 pm

    Remember: Spirit’s parser is greedy. Which means that if you do qi::omit[ <something> ], it will continue to omit characters until the <something> is no longer met. Since <something> is literally anything (char_ matches any character, so *char_ matches all characters), it will eat the entire rest of the string. Then it will raise an error, because it never got to “ChannelState: “.

    Your way of doing it simply won’t work. You have to have some cut-off switch to stop the *char_ from eating everything.

    I don’t see why you don’t just parse them all into a std::map, rather than doing it piecemeal. Then you can just pick out the elements you want. You say that you don’t want some elements yet, so just ignore them.

    This would be done as follows:

    //Includes
    #include <boost/spirit/include/qi.hpp>
    #include <boost/fusion/adapted/std_pair.hpp>
    
    //Code
    using namespace boost::spirit;
    using ascii::char_;
    using ascii::string;
    
    qi::rule<std::string::iterator, std::pair<std::string, std::string>() > pair_rule =
      *(char_ - ':') >> ':' >>
      qi::omit[*ascii::space] >>
      *(char_ - eol) >> (eol || eoi);
    
    qi::rule<std::string::iterator, std::map<std::string, std::string>() > map_rule =
      +pair_rule;
    
    std::map<std::string, std::string> v;
    bool r = qi::parse(test.begin(), test.end(), map_rule, v); 
    

    Note that this works on Boost 1.47. I would suspect it would fail on earlier versions.

    Boost version 1.42 compiler g++ 4.4 Spirit 0x2020

    Those are rather old. You should consider upgrading. Boost is up to 1.47 now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to parse a YouTube feed using PHP simplexml_load_file(); I am able to access
I'm trying to parse some data in a fixed format text file where each
I am trying to parse xml file and get no errors but when trying
I trying to parse a data in a MySql Format, I ran across SimpleDateFormat
Trying to parse a csv file that has all the data wrapped in double
I am trying to parse tab separated data files generated by our services using
When trying to parse the following file, I get the error [10,4]: [ERR 101]
I am trying to parse a given textfile, but so far, my program does
Am trying to parse this HTML document to get the contents of flight, time,
I'm trying to parse JSON with jQuery I get from a remote server through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.