I'd like to read from a std::istream
until a certain sequence of characters is found, i.e., I'd like to implement the following interface:
void read_until (std::istream &is, std::string_view needle);
Using std::istreambuf_iterator
, I believe this is equivalent to a combination of std::search
on a single-pass iterator. Unfortunately, the std::boyer_moore_searcher
needs random-access iterators.
Are there any easy implementations of the above interface using the C++ standard library (and a bit of memory proportional to the size of sv
), or do I have to code it myself?
std::search
works on any forward iterator. Now, youristream
iterator isn't a forward iterator, but you don't need random access at least. – Ardellardella