Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-19 08:38:26

From: "John Maddock" <John_Maddock_at_[hidden]>

> >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
> >the stream in the state it was before (if possible), that is, I either
> >its position back if the operation is supported or call unget()
> >the appropriate number of times (I'd have to know how many characters the
> >regex library has extracted.)
> 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
> Depending on how many characters are extracted, you may or may not be
> to successfully put characters back (unless I'm misunderstanding how the
> iostream lib works).

If the stream is seekable, I should be able to seek back to the original
position; if it's not, I'll try unget()'ing. If this doesn't work, it's up
to me to handle the error.

Let's split the question into two parts:

First, how do I use boost.regex to match several patterns, determining the
pattern that produces the longest match?

Second, how do I convince the library to work with a istream? Read N
characters, match, read N * 2 characters, match, and so on? There has to be
a better way. :-) I don't need an iterator pair back, only the number of
reads the library has performed.

Actually in this particular case I don't even need the exact match length,
only which pattern produces the longest match.

Peter Dimov
Multi Media Ltd.

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