5#ifndef QSTRINGTOKENIZER_H
6#define QSTRINGTOKENIZER_H
8#include <QtCore/qnamespace.h>
9#include <QtCore/qcontainerfwd.h>
14template <
typename,
typename>
class QStringBuilder;
26 {
return lhs.start == rhs.start && lhs.end == rhs.end && lhs.extra == rhs.extra; }
35template <
typename Haystack,
typename Needle>
44 inline next_result toFront()
const noexcept {
return next({}); }
46 constexpr explicit QStringTokenizerBase(Haystack haystack, Needle needle, Qt::SplitBehavior sb, Qt::CaseSensitivity cs)
noexcept
60 : tokenizer{&t}, current{t.toFront()} {}
71 [[
nodiscard]]
constexpr const Haystack*
operator->()
const {
return Q_ASSERT(current.ok), ¤t.value; }
78 {
return !lhs.current.ok; }
80 {
return !operator==(lhs,
sentinel{}); }
82 {
return !rhs.current.ok; }
84 {
return !operator==(
sentinel{}, rhs); }
88 current = tokenizer->next(current.state);
111QT_BEGIN_INCLUDE_NAMESPACE
112#include <QtCore/qstringview.h>
113QT_END_INCLUDE_NAMESPACE
119 template <
typename String>
131 template <
typename LHS,
typename RHS>
133 template <
typename Char,
typename...Args>
135#ifdef __cpp_lib_string_view
136 template <
typename Char,
typename...Args>
137 struct ViewForImpl<
std::basic_string_view<Char, Args...>> :
ViewForImpl<Char*> {};
144 template <
typename String>
153 template <
typename String>
161 template <
typename Char,
typename...Args>
163 {
using type =
std::basic_string<Char, Args...>; };
166 template <
typename LHS,
typename RHS>
170 template <
typename StringLike>
185 constexpr T
view(T t)
const noexcept {
return t; }
189 template <
typename T>
203 template <
typename T>
207 template <
typename Arg>
210 {
return this->view(
std::forward<Arg>(a)); }
213 template <
typename T>
217 template <
typename Arg>
220 {
return this->view(
std::forward<Arg>(a)); }
233template <
typename Haystack,
typename Needle>
242 template <
typename Container,
typename HPin>
243 struct if_haystack_not_pinned_impl :
std::enable_if<
std::is_empty<HPin>::value,
bool> {};
244 template <
typename Container>
245 using if_haystack_not_pinned =
typename if_haystack_not_pinned_impl<Container, HPin>::type;
274 Qt::CaseSensitivity cs,
281 : HPin{
std::forward<Haystack>(haystack)},
282 NPin{
std::forward<Needle>(needle)},
292 : HPin{
std::forward<Haystack>(haystack)},
293 NPin{
std::forward<Needle>(needle)},
302 template<
typename Container =
QList<
value_type>, if_compatible_container<Container> =
true>
307 return std::forward<Container>(c);
309 template<
typename Container =
QList<
value_type>, if_compatible_container<Container> =
true,
310 if_haystack_not_pinned<Container> =
true>
315 return std::forward<Container>(c);
335 QtPrivate::Tok::PinFor<Haystack>,
336 QtPrivate::Tok::PinFor<Needle>
346#ifdef __cpp_deduction_guides
349template <
typename Haystack,
typename Needle>
350QStringTokenizer(Haystack&&, Needle&&)
352template <
typename Haystack,
typename Needle>
353QStringTokenizer(Haystack&&, Needle&&, Qt::SplitBehavior)
355template <
typename Haystack,
typename Needle>
356QStringTokenizer(Haystack&&, Needle&&, Qt::SplitBehavior, Qt::CaseSensitivity)
358template <
typename Haystack,
typename Needle>
359QStringTokenizer(Haystack&&, Needle&&, Qt::CaseSensitivity)
361template <
typename Haystack,
typename Needle>
362QStringTokenizer(Haystack&&, Needle&&, Qt::CaseSensitivity, Qt::SplitBehavior)
368template <
typename Haystack,
typename Needle,
typename...Flags>
369[[nodiscard]]
constexpr auto
374{
return QtPrivate::Tok::TokenizerResult<Haystack, Needle>{std::forward<Haystack>(h),
375 std::forward<Needle>(n),
378template <
typename Haystack,
typename Needle>
384 return {{},
false, state};
386 state.end = m_haystack.indexOf(m_needle, state.start + state.extra, m_cs);
388 if (state.end >= 0) {
390 result = m_haystack.sliced(state.start, state.end - state.start);
392 state.start = state.end + ns;
393 state.extra = (ns == 0 ? 1 : 0);
396 result = m_haystack.sliced(state.start);
398 if ((m_sb & Qt::SkipEmptyParts) && result.isEmpty())
400 return {result,
true, state};
~QStringTokenizerBaseBase()=default
constexpr QStringTokenizerBaseBase(Qt::SplitBehavior sb, Qt::CaseSensitivity cs) noexcept
friend constexpr bool operator!=(const iterator &lhs, sentinel) noexcept
const value_type * pointer
const value_type & reference
constexpr const Haystack * operator->() const
friend constexpr bool operator==(const iterator &lhs, sentinel) noexcept
iterator() noexcept=default
constexpr const Haystack & operator*() const
std::forward_iterator_tag iterator_category
friend constexpr bool operator!=(sentinel, const iterator &rhs) noexcept
friend constexpr bool operator==(sentinel, const iterator &rhs) noexcept
friend constexpr bool operator==(sentinel, sentinel) noexcept
friend constexpr bool operator!=(sentinel, sentinel) noexcept
typename iterator::pointer pointer
constexpr sentinel end() const noexcept
iterator begin() const noexcept
typename iterator::difference_type difference_type
constexpr QStringTokenizerBase(Haystack haystack, Needle needle, Qt::SplitBehavior sb, Qt::CaseSensitivity cs) noexcept
iterator cbegin() const noexcept
typename iterator::reference reference
typename iterator::value_type value_type
reference const_reference
constexpr sentinel cend() const noexcept
Container toContainer(Container &&c={}) const &&
Container toContainer(Container &&c={}) const &
constexpr QStringTokenizer(Haystack haystack, Needle needle, Qt::CaseSensitivity cs, Qt::SplitBehavior sb=Qt::KeepEmptyParts) noexcept(std::is_nothrow_copy_constructible< QStringTokenizer >::value)
\typealias QStringTokenizer::sentinel
constexpr qsizetype tokenSize(const String &s) noexcept
typename ViewForImpl< typename std::decay< String >::type >::type ViewFor
constexpr qsizetype tokenSize(QChar) noexcept
typename PinForImpl< typename std::remove_cv< StringLike >::type >::type PinFor
constexpr auto qTokenize(Haystack &&h, Needle &&n, Flags...flags) noexcept(QtPrivate::Tok::is_nothrow_constructible_from< Haystack, Needle >::value) -> decltype(QtPrivate::Tok::TokenizerResult< Haystack, Needle >{std::forward< Haystack >(h), std::forward< Needle >(n), flags...})
friend constexpr bool operator!=(tokenizer_state lhs, tokenizer_state rhs) noexcept
friend constexpr bool operator==(tokenizer_state lhs, tokenizer_state rhs) noexcept
constexpr auto haystackView(Arg &&a) noexcept -> decltype(this->view(std::forward< Arg >(a)))
constexpr auto needleView(Arg &&a) noexcept -> decltype(this->view(std::forward< Arg >(a)))
std::basic_string< Char, Args... > type
constexpr QStringView view(const T &) const noexcept
constexpr Pinning(T &&s) noexcept
constexpr Pinning(const T &) noexcept
constexpr T view(T t) const noexcept