util/StringSplit: add Partition()

This commit is contained in:
Max Kellermann 2022-07-05 14:33:32 +02:00 committed by Max Kellermann
parent 485ad583a0
commit 7600ad7cac
1 changed files with 19 additions and 0 deletions

View File

@ -31,6 +31,25 @@
#include <string_view>
template<typename T>
constexpr std::pair<std::basic_string_view<T>, std::basic_string_view<T>>
Partition(const std::basic_string_view<T> haystack,
const typename std::basic_string_view<T>::size_type position) noexcept
{
return {
haystack.substr(0, position),
haystack.substr(position),
};
}
template<typename T>
constexpr std::pair<std::basic_string_view<T>, std::basic_string_view<T>>
Partition(const std::basic_string_view<T> haystack,
const typename std::basic_string_view<T>::const_pointer position) noexcept
{
return Partition(haystack, std::distance(haystack.data(), position));
}
template<typename T>
[[gnu::pure]]
std::pair<std::basic_string_view<T>, std::basic_string_view<T>>