3#ifndef QSTRINGTOKENIZER_H
4#define QSTRINGTOKENIZER_H
6#include <QtCore/qnamespace.h>
7#include <QtCore/qcontainerfwd.h>
12template <
typename,
typename>
class QStringBuilder;
24 {
return lhs.start == rhs.start && lhs.end == rhs.end && lhs.extra == rhs.extra; }
33template <
typename Haystack,
typename Needle>
42 inline next_result toFront()
const noexcept {
return next({}); }
44 constexpr explicit QStringTokenizerBase(Haystack haystack, Needle needle, Qt::SplitBehavior sb, Qt::CaseSensitivity cs)
noexcept
58 : tokenizer{&t}, current{t.toFront()} {}
61 using value_type = Haystack;
62 using pointer =
const value_type*;
63 using reference =
const value_type&;
64 using iterator_category =
std::forward_iterator_tag;
69 [[
nodiscard]]
constexpr const Haystack*
operator->()
const {
return Q_ASSERT(current.ok), ¤t.value; }
76 {
return !lhs.current.ok; }
78 {
return !operator==(lhs,
sentinel{}); }
80 {
return !rhs.current.ok; }
82 {
return !operator==(
sentinel{}, rhs); }
86 current = tokenizer->next(current.state);
91 using size_type =
std::size_t;
92 using difference_type =
typename iterator::difference_type;
93 using value_type =
typename iterator::value_type;
95 using const_pointer = pointer;
96 using reference =
typename iterator::reference;
97 using const_reference = reference;
109QT_BEGIN_INCLUDE_NAMESPACE
110#include <QtCore/qstringview.h>
111QT_END_INCLUDE_NAMESPACE
117 template <
typename String>
118 constexpr qsizetype size(
const String &s)
noexcept {
return static_cast<qsizetype>(s.size()); }
129 template <
typename LHS,
typename RHS>
131 template <
typename Char,
typename...Args>
133#ifdef __cpp_lib_string_view
134 template <
typename Char,
typename...Args>
142 template <
typename String>
151 template <
typename String>
159 template <
typename Char,
typename...Args>
161 {
using type =
std::basic_string<Char, Args...>; };
164 template <
typename LHS,
typename RHS>
168 template <
typename StringLike>
169 using PinFor =
typename PinForImpl<
typename std::remove_cv<StringLike>::type>::type;
183 constexpr T
view(T t)
const noexcept {
return t; }
187 template <
typename T>
201 template <
typename T>
205 template <
typename Arg>
207 ->
decltype(
this->view(
std::forward<Arg>(a)))
208 {
return this->view(
std::forward<Arg>(a)); }
211 template <
typename T>
215 template <
typename Arg>
217 ->
decltype(
this->view(
std::forward<Arg>(a)))
218 {
return this->view(
std::forward<Arg>(a)); }
231template <
typename Haystack,
typename Needle>
240 template <
typename Container,
typename HPin>
241 struct if_haystack_not_pinned_impl :
std::enable_if<
std::is_empty<HPin>::value,
bool> {};
242 template <
typename Container>
243 using if_haystack_not_pinned =
typename if_haystack_not_pinned_impl<Container, HPin>::type;
272 Qt::CaseSensitivity cs,
279 : HPin{
std::forward<Haystack>(haystack)},
280 NPin{
std::forward<Needle>(needle)},
290 : HPin{
std::forward<Haystack>(haystack)},
291 NPin{
std::forward<Needle>(needle)},
300 template<
typename Container =
QList<
value_type>, if_compatible_container<Container> =
true>
305 return std::forward<Container>(c);
307 template<
typename Container =
QList<
value_type>, if_compatible_container<Container> =
true,
308 if_haystack_not_pinned<Container> =
true>
313 return std::forward<Container>(c);
333 QtPrivate::Tok::PinFor<Haystack>,
334 QtPrivate::Tok::PinFor<Needle>
344#ifdef __cpp_deduction_guides
347template <
typename Haystack,
typename Needle>
348QStringTokenizer(Haystack&&, Needle&&)
350template <
typename Haystack,
typename Needle>
351QStringTokenizer(Haystack&&, Needle&&, Qt::SplitBehavior)
353template <
typename Haystack,
typename Needle>
354QStringTokenizer(Haystack&&, Needle&&, Qt::SplitBehavior, Qt::CaseSensitivity)
356template <
typename Haystack,
typename Needle>
357QStringTokenizer(Haystack&&, Needle&&, Qt::CaseSensitivity)
359template <
typename Haystack,
typename Needle>
360QStringTokenizer(Haystack&&, Needle&&, Qt::CaseSensitivity, Qt::SplitBehavior)
366template <
typename Haystack,
typename Needle,
typename...Flags>
367[[nodiscard]]
constexpr auto
372{
return QtPrivate::Tok::TokenizerResult<Haystack, Needle>{std::forward<Haystack>(h),
373 std::forward<Needle>(n),
376template <
typename Haystack,
typename Needle>
382 return {{},
false, state};
384 state.end = m_haystack.indexOf(m_needle, state.start + state.extra, m_cs);
386 if (state.end >= 0) {
388 result = m_haystack.sliced(state.start, state.end - state.start);
390 state.start = state.end + ns;
391 state.extra = (ns == 0 ? 1 : 0);
394 result = m_haystack.sliced(state.start);
396 if ((m_sb & Qt::SkipEmptyParts) && result.isEmpty())
398 return {result,
true, state};
~QStringTokenizerBaseBase()=default
constexpr QStringTokenizerBaseBase(Qt::SplitBehavior sb, Qt::CaseSensitivity cs) noexcept
friend constexpr bool operator!=(const iterator &lhs, sentinel) noexcept
constexpr const Haystack * operator->() const
friend constexpr bool operator==(const iterator &lhs, sentinel) noexcept
iterator() noexcept=default
constexpr const Haystack & operator*() const
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
constexpr sentinel end() const noexcept
iterator begin() const noexcept
constexpr QStringTokenizerBase(Haystack haystack, Needle needle, Qt::SplitBehavior sb, Qt::CaseSensitivity cs) noexcept
iterator cbegin() const noexcept
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
Combined button and popup list for selecting options.
constexpr qsizetype size(QChar) noexcept
constexpr qsizetype size(const String &s) noexcept
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)))
constexpr QStringView view(const T &) const noexcept
constexpr Pinning(T &&s) noexcept
constexpr Pinning(const T &) noexcept
constexpr T view(T t) const noexcept