From f5c31262011f7fbcbff5ee91b0df22e4373dd2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Wed, 14 May 2014 10:56:44 +0200 Subject: Add QString::splitRef functions. The functions can be used to optimize code that do not need to use the split results as QString directly. [ChangeLog][QtCore] QString can now split a string to a list of QStringRef. Change-Id: Ic2dc929e1fba82f9a060e37c51068a301cb5b866 Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart --- src/corelib/tools/qstring.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/corelib/tools/qstring.cpp') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index e8eb04b598..fdde0955dd 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -6668,6 +6668,28 @@ QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseS return splitString(*this, &QString::mid, sep, behavior, cs, sep.size()); } +/*! + Splits the string into substring references wherever \a sep occurs, and + returns the list of those strings. If \a sep does not match + anywhere in the string, splitRef() returns a single-element vector + containing this string reference. + + \a cs specifies whether \a sep should be matched case + sensitively or case insensitively. + + If \a behavior is QString::SkipEmptyParts, empty entries don't + appear in the result. By default, empty entries are kept. + + \note All references are valid as long this string is alive. Destroying this + string will cause all references be dangling pointers. + + \since 5.4 + \sa QStringRef split() +*/ +QVector QString::splitRef(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const +{ + return splitString >(*this, &QString::midRef, sep, behavior, cs, sep.size()); +} /*! \overload */ @@ -6676,6 +6698,15 @@ QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivit return splitString(*this, &QString::mid, sep, behavior, cs, 1); } +/*! + \overload + \since 5.4 +*/ +QVector QString::splitRef(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const +{ + return splitString >(*this, &QString::midRef, sep, behavior, cs, 1); +} + #ifndef QT_NO_REGEXP namespace { template @@ -6729,6 +6760,25 @@ QStringList QString::split(const QRegExp &rx, SplitBehavior behavior) const { return splitString(*this, &QString::mid, rx, behavior); } + +/*! + \overload + \since 5.4 + + Splits the string into substring references wherever the regular expression + \a rx matches, and returns the list of those strings. If \a rx + does not match anywhere in the string, splitRef() returns a + single-element vector containing this string reference. + + \note All references are valid as long this string is alive. Destroying this + string will cause all references be dangling pointers. + + \sa QStringRef split() +*/ +QVector QString::splitRef(const QRegExp &rx, SplitBehavior behavior) const +{ + return splitString >(*this, &QString::midRef, rx, behavior); +} #endif #ifndef QT_NO_REGULAREXPRESSION @@ -6793,6 +6843,25 @@ QStringList QString::split(const QRegularExpression &re, SplitBehavior behavior) { return splitString(*this, &QString::mid, re, behavior); } + +/*! + \overload + \since 5.4 + + Splits the string into substring references wherever the regular expression + \a re matches, and returns the list of those strings. If \a re + does not match anywhere in the string, splitRef() returns a + single-element vector containing this string reference. + + \note All references are valid as long this string is alive. Destroying this + string will cause all references be dangling pointers. + + \sa split() QStringRef +*/ +QVector QString::splitRef(const QRegularExpression &re, SplitBehavior behavior) const +{ + return splitString >(*this, &QString::midRef, re, behavior); +} #endif // QT_BOOTSTRAPPED #endif // QT_NO_REGULAREXPRESSION -- cgit v1.2.3