I'd like to have a std::getline
function which is able to stop if it encounters any of the characters listed in a string, so I came up with the following:
std::istream& read_until(std::istream& is, std::string& s, const std::string& list) {
s.clear();
while (is.peek() && is && list.find(is.peek()) == list.npos) {
s += is.get();
}
return is;
}
The fact that it leaves the terminating character on the stream is the desired behavior. This works, but it's ugly and doesn't feel the right way to go. I'd like to ask if you see any clear mistake or if you have a better way of handling this.