view: add split_on overload for array delimiters
This commit is contained in:
parent
94bc72d3a1
commit
a2259013f5
37
view.hpp
37
view.hpp
@ -793,9 +793,9 @@ namespace cruft {
|
|||||||
auto const pos = std::find (std::begin (buffer), std::end (buffer), value);
|
auto const pos = std::find (std::begin (buffer), std::end (buffer), value);
|
||||||
if (pos == std::end (buffer))
|
if (pos == std::end (buffer))
|
||||||
return {
|
return {
|
||||||
buffer,
|
buffer,
|
||||||
{std::end (buffer), std::end (buffer)}
|
{std::end (buffer), std::end (buffer)}
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{ buffer.begin (), pos, },
|
{ buffer.begin (), pos, },
|
||||||
@ -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
|
/// 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