Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QStringTokenizer< Haystack, Needle > Class Template Reference

\inmodule QtCore More...

#include <qstringtokenizer.h>

+ Inheritance diagram for QStringTokenizer< Haystack, Needle >:
+ Collaboration diagram for QStringTokenizer< Haystack, Needle >:

Public Types

using value_type = typename Base::value_type
 
using difference_type = typename Base::difference_type
 
using size_type = typename Base::size_type
 
using reference = typename Base::reference
 
using const_reference = typename Base::const_reference
 
using pointer = typename Base::pointer
 
using const_pointer = typename Base::const_pointer
 
using iterator = typename Base::iterator
 
using const_iterator = typename Base::const_iterator
 \typealias QStringTokenizer::value_type
 
using sentinel = typename Base::sentinel
 
- Public Types inherited from QStringTokenizerBase< Haystack, Needle >
using const_iterator = iterator
 
using size_type = std::size_t
 
using difference_type = typename iterator::difference_type
 
using value_type = typename iterator::value_type
 
using pointer = typename iterator::pointer
 
using const_pointer = pointer
 
using reference = typename iterator::reference
 
using const_reference = reference
 

Public Member Functions

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 QStringTokenizer (Haystack haystack, Needle needle, Qt::SplitBehavior sb=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept(std::is_nothrow_copy_constructible< QStringTokenizer >::value)
 Constructs a string tokenizer that splits the string haystack into substrings wherever needle occurs, and allows iteration over those strings as they are found.
 
template<typename Container = QList<value_type>, if_compatible_container< Container > = true>
Container toContainer (Container &&c={}) const &
 
template<typename Container = QList<value_type>, if_compatible_container< Container > = true, if_haystack_not_pinned< Container > = true>
Container toContainer (Container &&c={}) const &&
 
- Public Member Functions inherited from QStringTokenizerBase< Haystack, Needle >
constexpr QStringTokenizerBase (Haystack haystack, Needle needle, Qt::SplitBehavior sb, Qt::CaseSensitivity cs) noexcept
 
iterator begin () const noexcept
 
iterator cbegin () const noexcept
 
constexpr sentinel end () const noexcept
 
constexpr sentinel cend () const noexcept
 

Related Symbols

(Note that these are not member symbols.)

template< typename Haystack, typename Needle, typename...Flags > auto qTokenize (Haystack &&haystack, Needle &&needle, Flags...flags)
 

Additional Inherited Members

- Protected Member Functions inherited from QStringTokenizerBaseBase
 ~QStringTokenizerBaseBase ()=default
 
constexpr QStringTokenizerBaseBase (Qt::SplitBehavior sb, Qt::CaseSensitivity cs) noexcept
 
- Protected Attributes inherited from QStringTokenizerBaseBase
Qt::SplitBehavior m_sb
 
Qt::CaseSensitivity m_cs
 

Detailed Description

template<typename Haystack, typename Needle>
class QStringTokenizer< Haystack, Needle >

\inmodule QtCore

Since
6.0

The QStringTokenizer class splits strings into tokens along given separators. \reentrant

Splits a string into substrings wherever a given separator occurs, returning a (lazily constructed) list of those strings. If the separator does not match anywhere in the string, produces a single-element list containing this string. If the separator is empty, QStringTokenizer produces an empty string, followed by each of the string's characters, followed by another empty string. The two enumerations Qt::SplitBehavior and Qt::CaseSensitivity further control the output.

QStringTokenizer drives QStringView::tokenize(), but you can use it directly, too:

for (auto it : QStringTokenizer{string, separator})
use(*it);
\inmodule QtCore
QSet< QString >::iterator it
[0]
GLsizei const GLchar *const * string
[0]
Definition qopenglext.h:694
Note
You should never, ever, name the template arguments of a QStringTokenizer explicitly. You may write {QStringTokenizer{string, separator}} (without template arguments), or use the qTokenize() function, or the QStringView::split() or QLatin1StringView::split() member functions and store the return value only in {auto} variables:
auto result = string.split(sep);
GLuint64EXT * result
[6]
static constexpr QChar sep

This is because the template arguments of QStringTokenizer have a very subtle dependency on the specific string and separator types from with which they are constructed, and they don't usually correspond to the actual types passed.

Definition at line 232 of file qstringtokenizer.h.

Member Typedef Documentation

◆ const_iterator

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::const_iterator = typename Base::const_iterator

\typealias QStringTokenizer::value_type

Alias for {const QStringView} or {const QLatin1StringView}, depending on the tokenizer's Haystack template argument.

\typealias QStringTokenizer::difference_type

Alias for qsizetype.

\typealias QStringTokenizer::size_type

Alias for qsizetype.

\typealias QStringTokenizer::reference

Alias for {value_type &}.

QStringTokenizer does not support mutable references, so this is the same as const_reference.

\typealias QStringTokenizer::const_reference

Alias for {value_type &}.

\typealias QStringTokenizer::pointer

Alias for {value_type *}.

QStringTokenizer does not support mutable iterators, so this is the same as const_pointer.

\typealias QStringTokenizer::const_pointer

Alias for {value_type *}.

\typealias QStringTokenizer::iterator

This typedef provides an STL-style const iterator for QStringTokenizer.

QStringTokenizer does not support mutable iterators, so this is the same as const_iterator.

See also
const_iterator

This typedef provides an STL-style const iterator for QStringTokenizer.

See also
iterator

Definition at line 261 of file qstringtokenizer.h.

◆ const_pointer

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::const_pointer = typename Base::const_pointer

Definition at line 259 of file qstringtokenizer.h.

◆ const_reference

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::const_reference = typename Base::const_reference

Definition at line 257 of file qstringtokenizer.h.

◆ difference_type

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::difference_type = typename Base::difference_type

Definition at line 254 of file qstringtokenizer.h.

◆ iterator

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::iterator = typename Base::iterator

Definition at line 260 of file qstringtokenizer.h.

◆ pointer

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::pointer = typename Base::pointer

Definition at line 258 of file qstringtokenizer.h.

◆ reference

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::reference = typename Base::reference

Definition at line 256 of file qstringtokenizer.h.

◆ sentinel

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::sentinel = typename Base::sentinel

Definition at line 262 of file qstringtokenizer.h.

◆ size_type

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::size_type = typename Base::size_type

Definition at line 255 of file qstringtokenizer.h.

◆ value_type

template<typename Haystack , typename Needle >
using QStringTokenizer< Haystack, Needle >::value_type = typename Base::value_type

Definition at line 253 of file qstringtokenizer.h.

Constructor & Destructor Documentation

◆ QStringTokenizer() [1/2]

template<typename Haystack , typename Needle >
QStringTokenizer< Haystack, Needle >::QStringTokenizer ( Haystack haystack,
Needle needle,
Qt::CaseSensitivity cs,
Qt::SplitBehavior sb = Qt::KeepEmptyParts )
inlineexplicitconstexprnoexcept

\typealias QStringTokenizer::sentinel

This typedef provides an STL-style sentinel for QStringTokenizer::iterator and QStringTokenizer::const_iterator.

See also
const_iterator

Definition at line 271 of file qstringtokenizer.h.

◆ QStringTokenizer() [2/2]

template<typename Haystack , typename Needle >
QStringTokenizer< Haystack, Needle >::QStringTokenizer ( Haystack haystack,
Needle needle,
Qt::SplitBehavior sb = Qt::KeepEmptyParts,
Qt::CaseSensitivity cs = Qt::CaseSensitive )
inlineexplicitconstexprnoexcept

Constructs a string tokenizer that splits the string haystack into substrings wherever needle occurs, and allows iteration over those strings as they are found.

If needle does not match anywhere in haystack, a single element containing haystack is produced.

cs specifies whether needle should be matched case sensitively or case insensitively.

If sb is Qt::SkipEmptyParts, empty entries don't appear in the result. By default, empty entries are included.

See also
QStringView::split(), QString::split(), Qt::CaseSensitivity, Qt::SplitBehavior

Definition at line 286 of file qstringtokenizer.h.

Member Function Documentation

◆ toContainer() [1/2]

template<typename Haystack , typename Needle >
template<typename Container = QList<value_type>, if_compatible_container< Container > = true>
Container QStringTokenizer< Haystack, Needle >::toContainer ( Container && c = {}) const &
inline

Definition at line 301 of file qstringtokenizer.h.

◆ toContainer() [2/2]

template<typename Haystack , typename Needle >
template<typename Container = QList<value_type>, if_compatible_container< Container > = true, if_haystack_not_pinned< Container > = true>
Container QStringTokenizer< Haystack, Needle >::toContainer ( Container && c = {}) const &&
inline

Definition at line 309 of file qstringtokenizer.h.

Friends And Related Symbol Documentation

◆ qTokenize()

template<typename Haystack , typename Needle >
template< typename Haystack, typename Needle, typename...Flags > auto qTokenize ( Haystack && haystack,
Needle && needle,
Flags... flags )
related
Since
6.0

Factory function for a QStringTokenizer that splits the string haystack into substrings wherever needle occurs, and allows iteration over those strings as they are found. If needle does not match anywhere in haystack, a single element containing haystack is produced.

Pass values from Qt::CaseSensitivity and Qt::SplitBehavior enumerators as flags to modify the behavior of the tokenizer.

Definition at line 368 of file qstringtokenizer.h.

References qTokenize().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: