view: add split_on

This commit is contained in:
Danny Robson 2021-11-22 11:16:10 +10:00
parent ce826e664f
commit 0854405b2c

View File

@ -750,6 +750,27 @@ namespace cruft {
}
///////////////////////////////////////////////////////////////////////////
template <typename IteratorT>
std::pair<view<IteratorT>, view<IteratorT>>
split_on (
view<IteratorT> const buffer,
typename std::iterator_traits<IteratorT>::value_type const value
) {
auto const pos = std::find (std::begin (buffer), std::end (buffer), value);
if (pos == std::end (buffer))
return {
buffer,
{std::end (buffer), std::end (buffer)}
};
return {
{ buffer.begin (), pos, },
{ pos + 1, buffer.end () }
};
}
///////////////////////////////////////////////////////////////////////////
/// Returns a reference to a value of the designated type at the front of
/// the word-view. if there is insufficient data for the extraction an