view: add split_on
This commit is contained in:
parent
ce826e664f
commit
0854405b2c
21
view.hpp
21
view.hpp
@ -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
|
/// 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
|
/// the word-view. if there is insufficient data for the extraction an
|
||||||
|
Loading…
Reference in New Issue
Block a user