Boost logo

Boost :

Subject: Re: [boost] [xpressive] Concatenating two regular expressions into one?
From: Eric Niebler (eric_at_[hidden])
Date: 2012-03-14 21:33:02


On 3/13/2012 3:18 PM, Robert Dailey wrote:
> I have the following function:
>
> bool MimeDocument::GetMimeHeaderData( PMIMEENTITY entity,
> MimeHeaderData& header_data )
> {
> bool success = false;
>
> std::string headers;
> GetMimeEntityData( entity, MIME_ENTITY_DATA_HEADERS, headers );
>
> using namespace boost::xpressive;
>
> sregex content_disposition_re =
> icase("Content-Disposition:") >> +_s >> (s1=!as_xpr("inline;"))
> >> -*_ >> "size=" >> (s2=+_d) >> ';'
> ;
>
> sregex content_id_re =
> icase("Content-ID:") >> +_s >> '<' >> (s1=+_) >> '>'
> ;
>
> smatch what;
> if( regex_search( headers, what, content_disposition_re ) ) {
> header_data.is_inline = what[1] == "inline;";
> header_data.size = boost::lexical_cast<unsigned>( what[2] );
> success = true;
> }
>
> if( regex_search( headers, what, content_id_re ) ) {
> header_data.content_id = what[1];
> success = true;
> }
>
> return success;
> }
>
> Right now I use 2 sregex objects and search the MIME headers twice to find
> 2 different lines. Ideally I'd like to just use 1 regex and combine them,
> but I need to then somehow make it search between all lines, and then the
> order in which Content-Distribution and Content-ID appear in the headers
> may vary. Is it best to keep them separated like this, or can I concatenate
> the regular expressions into 1?

I could certainly come up with a way to combine them, I don't see a
particular need. My solution would be more complicated than what you
have shown. Is there a particular reason why you feel the code above is
insufficient?

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk