view: add split_on overload for array delimiters
This commit is contained in:
parent
94bc72d3a1
commit
a2259013f5
31
view.hpp
31
view.hpp
@ -804,6 +804,37 @@ namespace cruft {
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// Split a view at the first occurrence of the sub-string `value`.
|
||||
///
|
||||
/// If no occurrence was found the returned pair will be the original view
|
||||
/// and an empty view.
|
||||
template <typename IteratorT, std::size_t N>
|
||||
std::pair<view<IteratorT>, view<IteratorT>>
|
||||
split_on (
|
||||
view<IteratorT> const buffer,
|
||||
typename std::iterator_traits<IteratorT>::value_type (&value)[N]
|
||||
) {
|
||||
auto const pos = std::search (
|
||||
std::begin (buffer),
|
||||
std::end (buffer),
|
||||
std::begin (value),
|
||||
std::end (value)
|
||||
);
|
||||
|
||||
if (pos == std::end (buffer))
|
||||
return {
|
||||
buffer,
|
||||
{std::end (buffer), std::end (buffer)}
|
||||
};
|
||||
|
||||
return {
|
||||
{ buffer.begin (), pos, },
|
||||
{ pos + N, 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
|
||||
|
Loading…
Reference in New Issue
Block a user