Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2001-07-20 17:43:45

on 7/19/01 7:58 AM, John Maddock at John_Maddock_at_[hidden] wrote:

>> Let's assume that I have several regular expression patterns, p1, p2, ... pN.
>> I have an istream & (or a streambuf &.)
>> I want to determine which of the patterns, if any, matches the longest
>> sequence of characters at the current stream position (if there are several
>> that match the same number of characters I want the first), and then leave
>> the stream in the state it was before (if possible), that is, I either set
>> its position back if the operation is supported or call unget() repeatedly
>> the appropriate number of times (I'd have to know how many characters the
>> regex library has extracted.)
>> How can I do that using the boost.regex library? I don't see a simple way to
>> accomplish this.
> No because the library is not stream based, and doesn't work with
> input-iterators (since then it couldn't report what marched as a pair of
> iterators), a more serious problem though is how long is a piece of string?
> Depending on how many characters are extracted, you may or may not be able to
> successfully put characters back (unless I'm misunderstanding how the iostream
> lib works). Probably what you would need to do is create a kind of "caching
> iterator" - something that's constructed from an istream, and which carries
> out the seek (or putback) when it gets destructed, something like:
> {
> boost::stream_container sc(mystream);
> boost::regex_match(sc.begin(), sc.end(), my_regex);
> } // stream position reset here...

I think you would need something like a "caching iterator" instead. As you
said, there's no guarantee of how many characters can be pushed back, if
any. Even your reset idea may not work. Maybe a wrapper iostream that uses
something like a string for an extra buffer could be used. (Hmm, another
new class for

Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

Boost list run by bdawes at, gregod at, cpdaniel at, john at