In the documentation you can find a simple match function:
std::pair<iterator, bool>
match_whitespace(iterator begin, iterator end)
{
iterator i = begin;
while (i != end)
if (std::isspace(*i++))
return std::make_pair(i, true);
return std::make_pair(i, false);
}
In this case it matches any whitespace (change std::isspace according to what you want). Again in that documentation you can see a more complex event, it consumes the stream until it finds a specific character:
class match_char
{
public:
explicit match_char(char c) : c_(c) {}
template <typename Iterator>
std::pair<Iterator, bool> operator()(
Iterator begin, Iterator end) const
{
Iterator i = begin;
while (i != end)
if (c_ == *i++)
return std::make_pair(i, true);
return std::make_pair(i, false);
}
private:
char c_;
};
And the code to use that class:
// Function used for error handling
void handler(const boost::system::error_code& e, std::size_t size)
{
// Do something
}
// Example of call, it reads from inputStream to outputStreamBuff
// until the specified delimiter (";") is found
boost::asio::async_read_until(inputStream, outputStreamBuff,
match_char(';'), handler);