Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 2001-07-19 06:58:22

>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
>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
>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
boost::stream_container sc(mystream);
boost::regex_match(sc.begin(), sc.end(), my_regex);
} // stream position reset here...

- John Maddock

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