Boost logo

Boost :

From: Lorenzo Bettini (bettini_at_[hidden])
Date: 2005-06-02 06:30:25


John Maddock wrote:
>> that's exactly what I was looking for, but I hadn't found it in the
>> docs :-)
>>
>> as I understand, however, it's only available in 1.33
>
>
> Shucks, yes I think you're right about that, another approach would be
> to iterator through all the matches and join up the bits that didn't
> match with your replacement text. But, it's probably easier to grab a
> current cvs snapshot, and then upgrade to 1.33 as soon as it comes out
> (should be real soon now).

Indeed I used this solution

string
subst(const boost::regex &e, const string &s, const string &sub)
{
     string ret;

     boost::sregex_iterator i1(s.begin(), s.end(), e);
     boost::sregex_iterator i2;
     string suffix;

     if (i1 == i2)
         return s;
     // the exp is not in the string so we do not alter it.

     for (boost::sregex_iterator it = i1; it != i2; ++it) {
         string prefix = it->prefix();
         if (prefix.size())
             ret += prefix;

         suffix = it->suffix();
         ret += sub;
     }

     if (suffix.size())
         ret += suffix;

     return ret;
}

>
> Sorry about the false lead,

no problem :-)

by the way, I saw that it was also asked before (also by myself): do you
plan to implement the features "subexpressions that matched" so that one
does not have to iterate through all the subexpressions?

If I could help implementing that somehow I'd be happy

Lorenzo


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