diff options
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qlocale.h | 1 | ||||
-rw-r--r-- | src/corelib/text/qregularexpression.cpp | 2 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 1876 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 368 | ||||
-rw-r--r-- | src/corelib/text/qstringbuilder.cpp | 4 | ||||
-rw-r--r-- | src/corelib/text/qstringbuilder.h | 15 | ||||
-rw-r--r-- | src/corelib/text/qstringconverter_p.h | 4 | ||||
-rw-r--r-- | src/corelib/text/qstringtokenizer.h | 1 | ||||
-rw-r--r-- | src/corelib/text/qstringview.cpp | 20 | ||||
-rw-r--r-- | src/corelib/text/qstringview.h | 11 |
10 files changed, 42 insertions, 2260 deletions
diff --git a/src/corelib/text/qlocale.h b/src/corelib/text/qlocale.h index b0dab638ac..0ff2e4d469 100644 --- a/src/corelib/text/qlocale.h +++ b/src/corelib/text/qlocale.h @@ -65,7 +65,6 @@ class Q_CORE_EXPORT QLocale { Q_GADGET friend class QString; - friend class QStringRef; friend class QByteArray; friend class QIntValidator; friend class QDoubleValidatorPrivate; diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index db0f6907bb..c52a80e676 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -2191,7 +2191,7 @@ QString QRegularExpressionMatch::captured(QStringView name) const there is no capturing group named \a name, returns a null QStringView. \sa captured(), capturedStart(), capturedEnd(), capturedLength(), - QStringRef::isNull() + QStringView::isNull() */ QStringView QRegularExpressionMatch::capturedView(QStringView name) const { diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 6f8d2c87f5..3e7e9df35c 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -1849,7 +1849,7 @@ inline char qToLower(char ch) Such considerations, the configuration of such behavior or any mitigation are outside the scope of the Qt API. - \sa fromRawData(), QChar, QLatin1String, QByteArray, QStringRef + \sa fromRawData(), QChar, QLatin1String, QByteArray */ /*! \typedef QString::ConstIterator @@ -3930,14 +3930,15 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) qsizetype newLength = 0; // length of the new string, with all the replacements qsizetype lastEnd = 0; - QList<QStringRef> chunks; + QList<QStringView> chunks; + const QStringView copyView{ copy }, afterView{ after }; while (iterator.hasNext()) { QRegularExpressionMatch match = iterator.next(); qsizetype len; // add the part before the match len = match.capturedStart() - lastEnd; if (len > 0) { - chunks << copy.midRef(lastEnd, len); + chunks << copyView.mid(lastEnd, len); newLength += len; } @@ -3947,14 +3948,14 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) // part of "after" before the backreference len = backReference.pos - lastEnd; if (len > 0) { - chunks << after.midRef(lastEnd, len); + chunks << afterView.mid(lastEnd, len); newLength += len; } // backreference itself len = match.capturedLength(backReference.no); if (len > 0) { - chunks << copy.midRef(match.capturedStart(backReference.no), len); + chunks << copyView.mid(match.capturedStart(backReference.no), len); newLength += len; } @@ -3962,9 +3963,9 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) } // add the last part of the after string - len = after.length() - lastEnd; + len = afterView.length() - lastEnd; if (len > 0) { - chunks << after.midRef(lastEnd, len); + chunks << afterView.mid(lastEnd, len); newLength += len; } @@ -3972,18 +3973,18 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) } // 3. trailing string after the last match - if (copy.length() > lastEnd) { - chunks << copy.midRef(lastEnd); - newLength += copy.length() - lastEnd; + if (copyView.length() > lastEnd) { + chunks << copyView.mid(lastEnd); + newLength += copyView.length() - lastEnd; } // 4. assemble the chunks together resize(newLength); qsizetype i = 0; QChar *uc = data(); - for (const QStringRef &chunk : qAsConst(chunks)) { + for (const QStringView &chunk : qAsConst(chunks)) { qsizetype len = chunk.length(); - memcpy(uc + i, chunk.unicode(), len * sizeof(QChar)); + memcpy(uc + i, chunk.constData(), len * sizeof(QChar)); i += len; } @@ -4290,7 +4291,7 @@ qsizetype QString::count(const QRegularExpression &re) const QString QString::section(const QString &sep, qsizetype start, qsizetype end, SectionFlags flags) const { - const QList<QStringRef> sections = splitRef( + const QList<QStringView> sections = QStringView{ *this }.split( sep, Qt::KeepEmptyParts, (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive); const qsizetype sectionsSize = sections.size(); if (!(flags & SectionSkipEmpty)) { @@ -4315,7 +4316,7 @@ QString QString::section(const QString &sep, qsizetype start, qsizetype end, Sec QString ret; qsizetype first_i = start, last_i = end; for (qsizetype x = 0, i = 0; x <= end && i < sectionsSize; ++i) { - const QStringRef §ion = sections.at(i); + const QStringView §ion = sections.at(i); const bool empty = section.isEmpty(); if (x >= start) { if(x == start) @@ -4340,9 +4341,9 @@ QString QString::section(const QString &sep, qsizetype start, qsizetype end, Sec class qt_section_chunk { public: qt_section_chunk() {} - qt_section_chunk(qsizetype l, QStringRef s) : length(l), string(std::move(s)) {} + qt_section_chunk(qsizetype l, QStringView s) : length(l), string(std::move(s)) {} qsizetype length; - QStringRef string; + QStringView string; }; Q_DECLARE_TYPEINFO(qt_section_chunk, Q_MOVABLE_TYPE); @@ -4442,11 +4443,11 @@ QString QString::section(const QRegularExpression &re, qsizetype start, qsizetyp while (iterator.hasNext()) { QRegularExpressionMatch match = iterator.next(); m = match.capturedStart(); - sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, m - last_m))); + sections.append(qt_section_chunk(last_len, QStringView{ *this }.mid(last_m, m - last_m))); last_m = m; last_len = match.capturedLength(); } - sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, n - last_m))); + sections.append(qt_section_chunk(last_len, QStringView{ *this }.mid(last_m, n - last_m))); return extractSections(sections, start, end, flags); } @@ -5384,7 +5385,7 @@ QString QString::trimmed_helper(QString &str) If \a position is negative, it is equivalent to passing zero. - \sa chop(), resize(), left(), QStringRef::truncate() + \sa chop(), resize(), left(), QStringView::truncate() */ void QString::truncate(qsizetype pos) @@ -5406,7 +5407,7 @@ void QString::truncate(qsizetype pos) If you want to remove characters from the \e beginning of the string, use remove() instead. - \sa truncate(), resize(), remove(), QStringRef::chop() + \sa truncate(), resize(), remove(), QStringView::chop() */ void QString::chop(qsizetype n) { @@ -7184,24 +7185,6 @@ QStringList QString::split(const QString &sep, Qt::SplitBehavior behavior, Qt::C } /*! - Splits the string into substring references wherever \a sep occurs, and - returns the list of those strings. - - See QString::split() for how \a sep, \a behavior and \a cs interact to form - the result. - - \note All references are valid as long this string is alive. Destroying this - string will cause all references to be dangling pointers. - - \since 5.14 - \sa QStringRef split() -*/ -QList<QStringRef> QString::splitRef(const QString &sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const -{ - return splitString<QList<QStringRef>>(QStringRef(this), sep, behavior, cs); -} - -/*! \overload \since 5.14 */ @@ -7211,41 +7194,6 @@ QStringList QString::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensit } /*! - \overload - \since 5.14 -*/ -QList<QStringRef> QString::splitRef(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const -{ - return splitString<QList<QStringRef>>(QStringRef(this), QStringView(&sep, 1), behavior, cs); -} - -/*! - Splits the string into substrings references wherever \a sep occurs, and - returns the list of those strings. - - See QString::split() for how \a sep, \a behavior and \a cs interact to form - the result. - - \note All references are valid as long this string is alive. Destroying this - string will cause all references to be dangling pointers. - - \since 5.14 -*/ -QList<QStringRef> QStringRef::split(const QString &sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const -{ - return splitString<QList<QStringRef>>(*this, sep, behavior, cs); -} - -/*! - \overload - \since 5.14 -*/ -QList<QStringRef> QStringRef::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const -{ - return splitString<QList<QStringRef>>(*this, QStringView(&sep, 1), behavior, cs); -} - -/*! \fn QList<QStringView> QStringView::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const \fn QList<QStringView> QStringView::split(QStringView sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const @@ -7334,36 +7282,16 @@ QStringList QString::split(const QRegularExpression &re, Qt::SplitBehavior behav } /*! - \overload - \since 5.14 - - 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 list containing this string reference. - - \note All references are valid as long this string is alive. Destroying this - string will cause all references to be dangling pointers. - - \sa split() QStringRef -*/ -QList<QStringRef> QString::splitRef(const QRegularExpression &re, Qt::SplitBehavior behavior) const -{ - return splitString<QList<QStringRef>>(QStringRef(this), re, behavior); -} - -/*! \since 6.0 - Splits the string into substring views 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 list containing this string reference. - - \note All references are valid as long this string is alive. Destroying this - string will cause all references to be dangling pointers. + Splits the string into substring views wherever the regular expression \a re + matches, and returns the list of those strings. If \a re does not match + anywhere in the string, split() returns a single-element list containing + this string as view. - \sa split() QStringRef + \note The views in the returned list are sub-views of this view; as such, + they reference the same data as it and only remain valid for as long as that + data remains live. */ QList<QStringView> QStringView::split(const QRegularExpression &re, Qt::SplitBehavior behavior) const { @@ -8427,7 +8355,7 @@ bool QString::isSimpleText() const Returns \c true if the string is read right to left. - \sa QStringRef::isRightToLeft() + \sa QStringView::isRightToLeft() */ bool QString::isRightToLeft() const { @@ -9574,588 +9502,6 @@ QDataStream &operator>>(QDataStream &in, QString &str) } #endif // QT_NO_DATASTREAM - - - -/*! - \class QStringRef - \inmodule QtCore - \since 4.3 - \brief The QStringRef class provides a thin wrapper around QString substrings. - \reentrant - \ingroup tools - \ingroup string-processing - - QStringRef provides a read-only subset of the QString API. - - A string reference explicitly references a portion of a string() - with a given size(), starting at a specific position(). Calling - toString() returns a copy of the data as a real QString instance. - - This class is designed to improve the performance of substring - handling when manipulating substrings obtained from existing QString - instances. QStringRef avoids the memory allocation and reference - counting overhead of a standard QString by simply referencing a - part of the original string. This can prove to be advantageous in - low level code, such as that used in a parser, at the expense of - potentially more complex code. - - For most users, there are no semantic benefits to using QStringRef - instead of QString since QStringRef requires attention to be paid - to memory management issues, potentially making code more complex - to write and maintain. - - \warning A QStringRef is only valid as long as the referenced - string exists. If the original string is deleted, the string - reference points to an invalid memory location. - - We suggest that you only use this class in stable code where profiling - has clearly identified that performance improvements can be made by - replacing standard string operations with the optimized substring - handling provided by this class. - - \sa {Implicitly Shared Classes} -*/ - -/*! - \typedef QStringRef::size_type - \internal -*/ - -/*! - \typedef QStringRef::value_type - \internal -*/ - -/*! - \typedef QStringRef::const_pointer - \internal -*/ - -/*! - \typedef QStringRef::const_reference - \internal -*/ - -/*! - \typedef QStringRef::const_iterator - \since 5.4 - - \sa QStringRef::const_reverse_iterator -*/ - -/*! - \typedef QStringRef::const_reverse_iterator - \since 5.7 - - \sa QStringRef::const_iterator -*/ - -/*! - \fn QStringRef::QStringRef() - - Constructs an empty string reference. -*/ - -/*! \fn QStringRef::QStringRef(const QString *string, int position, int length) - -Constructs a string reference to the range of characters in the given -\a string specified by the starting \a position and \a length in characters. - -\warning This function exists to improve performance as much as possible, -and performs no bounds checking. For program correctness, \a position and -\a length must describe a valid substring of \a string. - -This means that the starting \a position must be positive or 0 and smaller -than \a string's length, and \a length must be positive or 0 but smaller than -the string's length minus the starting \a position; -i.e, 0 <= position < string->length() and -0 <= length <= string->length() - position must both be satisfied. -*/ - -/*! \fn QStringRef::QStringRef(const QString *string) - -Constructs a string reference to the given \a string. -*/ - -/*! \fn QStringRef::QStringRef(const QStringRef &other) - -Constructs a copy of the \a other string reference. - */ -/*! -\fn QStringRef::~QStringRef() - -Destroys the string reference. - -Since this class is only used to refer to string data, and does not take -ownership of it, no memory is freed when instances are destroyed. -*/ - -/*! - \fn int QStringRef::position() const - - Returns the starting position in the referenced string that is referred to - by the string reference. - - \sa size(), string() -*/ - -/*! - \fn int QStringRef::size() const - - Returns the number of characters referred to by the string reference. - Equivalent to length() and count(). - - \sa position(), string() -*/ -/*! - \fn int QStringRef::count() const - Returns the number of characters referred to by the string reference. - Equivalent to size() and length(). - - \sa position(), string() -*/ -/*! - \fn int QStringRef::length() const - Returns the number of characters referred to by the string reference. - Equivalent to size() and count(). - - \sa position(), string() -*/ - - -/*! - \fn bool QStringRef::isEmpty() const - - Returns \c true if the string reference has no characters; otherwise returns - \c false. - - A string reference is empty if its size is zero. - - \sa size() -*/ - -/*! - \fn bool QStringRef::isNull() const - - Returns \c true if this string reference does not reference a string or if - the string it references is null (i.e. QString::isNull() is true). - - \sa size() -*/ - -/*! - \fn const QString *QStringRef::string() const - - Returns a pointer to the string referred to by the string reference, or - 0 if it does not reference a string. - - \sa unicode() -*/ - - -/*! - \fn const QChar *QStringRef::unicode() const - - Returns a Unicode representation of the string reference. Since - the data stems directly from the referenced string, it is not - \\0'-terminated unless the string reference includes the string's - null terminator. - - \sa string() -*/ - -/*! - \fn const QChar *QStringRef::data() const - - Same as unicode(). -*/ - -/*! - \fn const QChar *QStringRef::constData() const - - Same as unicode(). -*/ - -/*! - \fn QStringRef::const_iterator QStringRef::begin() const - \since 5.4 - - Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in - the string. - - \sa cbegin(), constBegin(), end(), constEnd(), rbegin(), rend() -*/ - -/*! - \fn QStringRef::const_iterator QStringRef::cbegin() const - \since 5.4 - - Same as begin(). - - \sa begin(), constBegin(), cend(), constEnd(), rbegin(), rend() -*/ - -/*! - \fn QStringRef::const_iterator QStringRef::constBegin() const - \since 5.9 - - Same as begin(). - - \sa begin(), cend(), constEnd(), rbegin(), rend() -*/ - -/*! - \fn QStringRef::const_iterator QStringRef::end() const - \since 5.4 - - Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary - character after the last character in the list. - - \sa cbegin(), constBegin(), end(), constEnd(), rbegin(), rend() -*/ - -/*! \fn QStringRef::const_iterator QStringRef::cend() const - \since 5.4 - - Same as end(). - - \sa end(), constEnd(), cbegin(), constBegin(), rbegin(), rend() -*/ - -/*! \fn QStringRef::const_iterator QStringRef::constEnd() const - \since 5.9 - - Same as end(). - - \sa end(), cend(), cbegin(), constBegin(), rbegin(), rend() -*/ - -/*! - \fn QStringRef::const_reverse_iterator QStringRef::rbegin() const - \since 5.7 - - Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first - character in the string, in reverse order. - - \sa begin(), crbegin(), rend() -*/ - -/*! - \fn QStringRef::const_reverse_iterator QStringRef::crbegin() const - \since 5.7 - - Same as rbegin(). - - \sa begin(), rbegin(), rend() -*/ - -/*! - \fn QStringRef::const_reverse_iterator QStringRef::rend() const - \since 5.7 - - Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past - the last character in the string, in reverse order. - - \sa end(), crend(), rbegin() -*/ - - -/*! - \fn QStringRef::const_reverse_iterator QStringRef::crend() const - \since 5.7 - - Same as rend(). - - \sa end(), rend(), rbegin() -*/ - -/*! - Returns a copy of the string reference as a QString object. - - If the string reference is not a complete reference of the string - (meaning that position() is 0 and size() equals string()->size()), - this function will allocate a new string to return. - - \sa string() -*/ - -QString QStringRef::toString() const { - if (isNull()) - return QString(); - if (m_size && m_position == 0 && m_size == m_string->size()) - return *m_string; - return QString(m_string->unicode() + m_position, m_size); -} - - -/*! \relates QStringRef - - Returns \c true if string reference \a s1 is lexically equal to string reference \a s2; otherwise - returns \c false. -*/ -bool operator==(const QStringRef &s1,const QStringRef &s2) noexcept -{ - return s1.size() == s2.size() && qt_compare_strings(s1, s2, Qt::CaseSensitive) == 0; -} - -/*! \relates QStringRef - - Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise - returns \c false. -*/ -bool operator==(const QString &s1,const QStringRef &s2) noexcept -{ - return s1.size() == s2.size() && qt_compare_strings(s1, s2, Qt::CaseSensitive) == 0; -} - -/*! \relates QStringRef - - Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise - returns \c false. -*/ -bool operator==(QLatin1String s1, const QStringRef &s2) noexcept -{ - if (s1.size() != s2.size()) - return false; - - return qt_compare_strings(s2, s1, Qt::CaseSensitive) == 0; -} - -/*! - \relates QStringRef - - Returns \c true if string reference \a s1 is lexically less than - string reference \a s2; otherwise returns \c false. - - \sa {Comparing Strings} -*/ -bool operator<(const QStringRef &s1,const QStringRef &s2) noexcept -{ - return qt_compare_strings(s1, s2, Qt::CaseSensitive) < 0; -} - -/*!\fn bool operator<=(const QStringRef &s1,const QStringRef &s2) - - \relates QStringRef - - Returns \c true if string reference \a s1 is lexically less than - or equal to string reference \a s2; otherwise returns \c false. - - \sa {Comparing Strings} -*/ - -/*!\fn bool operator>=(const QStringRef &s1,const QStringRef &s2) - - \relates QStringRef - - Returns \c true if string reference \a s1 is lexically greater than - or equal to string reference \a s2; otherwise returns \c false. - - \sa {Comparing Strings} -*/ - -/*!\fn bool operator>(const QStringRef &s1,const QStringRef &s2) - - \relates QStringRef - - Returns \c true if string reference \a s1 is lexically greater than - string reference \a s2; otherwise returns \c false. - - \sa {Comparing Strings} -*/ - - -/*! - \fn const QChar QStringRef::at(int position) const - - Returns the character at the given index \a position in the - string reference. - - The \a position must be a valid index position in the string - (i.e., 0 <= \a position < size()). -*/ - -/*! - \fn QChar QStringRef::operator[](int position) const - \since 5.7 - - Returns the character at the given index \a position in the - string reference. - - The \a position must be a valid index position in the string - reference (i.e., 0 <= \a position < size()). - - \sa at() -*/ - -/*! - \fn QChar QStringRef::front() const - \since 5.10 - - Returns the first character in the string. - Same as \c{at(0)}. - - This function is provided for STL compatibility. - - \warning Calling this function on an empty string constitutes - undefined behavior. - - \sa back(), at(), operator[]() -*/ - -/*! - \fn QChar QStringRef::back() const - \since 5.10 - - Returns the last character in the string. - Same as \c{at(size() - 1)}. - - This function is provided for STL compatibility. - - \warning Calling this function on an empty string constitutes - undefined behavior. - - \sa front(), at(), operator[]() -*/ - -/*! - \fn void QStringRef::clear() - - Clears the contents of the string reference by making it null and empty. - - \sa isEmpty(), isNull() -*/ - -/*! - \fn QStringRef &QStringRef::operator=(const QStringRef &other) - - Assigns the \a other string reference to this string reference, and - returns the result. -*/ - -/*! - \fn QStringRef &QStringRef::operator=(const QString *string) - - Constructs a string reference to the given \a string and assigns it to - this string reference, returning the result. -*/ - -/*! - \fn bool QStringRef::operator==(const char * s) const - - \overload operator==() - - The \a s byte array is converted to a QStringRef using the - fromUtf8() function. This function stops conversion at the - first NUL character found, or the end of the byte array. - - You can disable this operator by defining \c - QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - Returns \c true if this string is lexically equal to the parameter - string \a s. Otherwise returns \c false. - - \sa QT_NO_CAST_FROM_ASCII -*/ - -/*! - \fn bool QStringRef::operator!=(const char * s) const - - \overload operator!=() - - The \a s const char pointer is converted to a QStringRef using - the fromUtf8() function. - - You can disable this operator by defining \c - QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - Returns \c true if this string is not lexically equal to the parameter - string \a s. Otherwise returns \c false. - - \sa QT_NO_CAST_FROM_ASCII -*/ - -/*! - \fn bool QStringRef::operator<(const char * s) const - - \overload operator<() - - The \a s const char pointer is converted to a QStringRef using - the fromUtf8() function. - - You can disable this operator by defining \c - QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - Returns \c true if this string is lexically smaller than the parameter - string \a s. Otherwise returns \c false. - - \sa QT_NO_CAST_FROM_ASCII -*/ - -/*! - \fn bool QStringRef::operator<=(const char * s) const - - \overload operator<=() - - The \a s const char pointer is converted to a QStringRef using - the fromUtf8() function. - - You can disable this operator by defining \c - QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - Returns \c true if this string is lexically smaller than or equal to the parameter - string \a s. Otherwise returns \c false. - - \sa QT_NO_CAST_FROM_ASCII -*/ - -/*! - \fn bool QStringRef::operator>(const char * s) const - - - \overload operator>() - - The \a s const char pointer is converted to a QStringRef using - the fromUtf8() function. - - You can disable this operator by defining \c - QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - Returns \c true if this string is lexically greater than the parameter - string \a s. Otherwise returns \c false. - - \sa QT_NO_CAST_FROM_ASCII -*/ - -/*! - \fn bool QStringRef::operator>= (const char * s) const - - \overload operator>=() - - The \a s const char pointer is converted to a QStringRef using - the fromUtf8() function. - - You can disable this operator by defining \c - QT_NO_CAST_FROM_ASCII when you compile your applications. This - can be useful if you want to ensure that all user-visible strings - go through QObject::tr(), for example. - - Returns \c true if this string is lexically greater than or equal to the - parameter string \a s. Otherwise returns \c false. - - \sa QT_NO_CAST_FROM_ASCII -*/ /*! \typedef QString::Data \internal @@ -10171,633 +9517,6 @@ bool operator<(const QStringRef &s1,const QStringRef &s2) noexcept \internal */ - - -/*! Appends the string reference to \a string, and returns a new -reference to the combined string data. - */ -QStringRef QStringRef::appendTo(QString *string) const -{ - if (!string) - return QStringRef(); - int pos = string->size(); - string->insert(pos, unicode(), size()); - return QStringRef(string, pos, size()); -} - -/*! - \fn int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) - \since 4.5 - - Compares the string \a s1 with the string \a s2 and returns an - integer less than, equal to, or greater than zero if \a s1 - is less than, equal to, or greater than \a s2. - - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. -*/ - -/*! - \fn int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) - \since 4.5 - \overload - - Compares the string \a s1 with the string \a s2 and returns an - integer less than, equal to, or greater than zero if \a s1 - is less than, equal to, or greater than \a s2. - - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. -*/ - -/*! - \fn int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) - \since 4.5 - \overload - - Compares the string \a s1 with the string \a s2 and returns an - integer less than, equal to, or greater than zero if \a s1 - is less than, equal to, or greater than \a s2. - - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. -*/ - -/*! - \overload - \fn int QStringRef::compare(const QString &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \since 4.5 - - Compares this string with the \a other string and returns an - integer less than, equal to, or greater than zero if this string - is less than, equal to, or greater than the \a other string. - - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. - - Equivalent to \c {compare(*this, other, cs)}. -*/ - -/*! - \overload - \fn int QStringRef::compare(const QStringRef &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \since 4.5 - - Compares this string with the \a other string and returns an - integer less than, equal to, or greater than zero if this string - is less than, equal to, or greater than the \a other string. - - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. - - Equivalent to \c {compare(*this, other, cs)}. -*/ - -/*! - \overload - \fn int QStringRef::compare(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \since 5.14 - - Compares this string with \a ch and returns an - integer less than, equal to, or greater than zero if this string - is less than, equal to, or greater than \a ch, interpreted as a string of length one. - - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. -*/ - -/*! - \overload - \fn int QStringRef::compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \since 4.5 - - Compares this string with the \a other string and returns an - integer less than, equal to, or greater than zero if this string - is less than, equal to, or greater than the \a other string. - - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. - - Equivalent to \c {compare(*this, other, cs)}. -*/ - -/*! - \overload - \fn int QStringRef::compare(const QByteArray &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \since 5.8 - - Compares this string with \a other and returns an - integer less than, equal to, or greater than zero if this string - is less than, equal to, or greater than the \a other byte array, - interpreted as a UTF-8 sequence. - - If \a cs is Qt::CaseSensitive, the comparison is case sensitive; - otherwise the comparison is case insensitive. - - Equivalent to \c {compare(*this, other, cs)}. -*/ - -/*! - \fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QString & s2) - \since 4.5 - - Compares \a s1 with \a s2 and returns an integer less than, equal - to, or greater than zero if \a s1 is less than, equal to, or - greater than \a s2. - - The comparison is performed in a locale- and also - platform-dependent manner. Use this function to present sorted - lists of strings to the user. - - \sa compare(), QLocale, {Comparing Strings} -*/ - -/*! - \fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QStringRef & s2) - \since 4.5 - \overload - - Compares \a s1 with \a s2 and returns an integer less than, equal - to, or greater than zero if \a s1 is less than, equal to, or - greater than \a s2. - - The comparison is performed in a locale- and also - platform-dependent manner. Use this function to present sorted - lists of strings to the user. - - \sa {Comparing Strings} -*/ - -/*! - \fn int QStringRef::localeAwareCompare(const QString &other) const - \since 4.5 - \overload - - Compares this string with the \a other string and returns an - integer less than, equal to, or greater than zero if this string - is less than, equal to, or greater than the \a other string. - - The comparison is performed in a locale- and also - platform-dependent manner. Use this function to present sorted - lists of strings to the user. - - \sa {Comparing Strings} -*/ - -/*! - \fn int QStringRef::localeAwareCompare(const QStringRef &other) const - \since 4.5 - \overload - - Compares this string with the \a other string and returns an - integer less than, equal to, or greater than zero if this string - is less than, equal to, or greater than the \a other string. - - The comparison is performed in a locale- and also - platform-dependent manner. Use this function to present sorted - lists of strings to the user. - - \sa {Comparing Strings} -*/ - -/*! - \fn QString &QString::append(QStringView str) - \since 6.0 - - Appends the given string view \a str to this string and returns the result. -*/ - -/*! - \fn QStringRef::left(int n) const - \since 5.2 - - Returns a substring reference to the \a n leftmost characters - of the string. - - If \a n is greater than or equal to size(), or less than zero, - a reference to the entire string is returned. - - \sa right(), mid(), startsWith(), chopped(), chop(), truncate() -*/ -QStringRef QStringRef::left(int n) const -{ - if (size_t(n) >= size_t(m_size)) - return *this; - return QStringRef(m_string, m_position, n); -} - -/*! - \since 4.4 - - Returns a substring reference to the \a n leftmost characters - of the string. - - If \a n is greater than or equal to size(), or less than zero, - a reference to the entire string is returned. - - \snippet qstring/main.cpp leftRef - - \sa left(), rightRef(), midRef(), startsWith() -*/ -QStringRef QString::leftRef(int n) const -{ - return QStringRef(this).left(n); -} - -/*! - \fn QStringRef::right(int n) const - \since 5.2 - - Returns a substring reference to the \a n rightmost characters - of the string. - - If \a n is greater than or equal to size(), or less than zero, - a reference to the entire string is returned. - - \sa left(), mid(), endsWith(), chopped(), chop(), truncate() -*/ -QStringRef QStringRef::right(int n) const -{ - if (size_t(n) >= size_t(m_size)) - return *this; - return QStringRef(m_string, m_size - n + m_position, n); -} - -/*! - \since 4.4 - - Returns a substring reference to the \a n rightmost characters - of the string. - - If \a n is greater than or equal to size(), or less than zero, - a reference to the entire string is returned. - - \snippet qstring/main.cpp rightRef - - \sa right(), leftRef(), midRef(), endsWith() -*/ -QStringRef QString::rightRef(int n) const -{ - return QStringRef(this).right(n); -} - -/*! - \fn QStringRef QStringRef::mid(int position, int n = -1) const - \since 5.2 - - Returns a substring reference to \a n characters of this string, - starting at the specified \a position. - - If the \a position exceeds the length of the string, a null - reference is returned. - - If there are less than \a n characters available in the string, - starting at the given \a position, or if \a n is -1 (default), the - function returns all characters from the specified \a position - onwards. - - \sa left(), right(), chopped(), chop(), truncate() -*/ -QStringRef QStringRef::mid(int pos, int n) const -{ - qsizetype p = pos; - qsizetype l = n; - using namespace QtPrivate; - switch (QContainerImplHelper::mid(m_size, &p, &l)) { - case QContainerImplHelper::Null: - return QStringRef(); - case QContainerImplHelper::Empty: - return QStringRef(m_string, 0, 0); - case QContainerImplHelper::Full: - return *this; - case QContainerImplHelper::Subset: - return QStringRef(m_string, p + m_position, l); - } - Q_UNREACHABLE(); - return QStringRef(); -} - -/*! - \fn QStringRef QStringRef::chopped(int len) const - \since 5.10 - - Returns a substring reference to the size() - \a len leftmost characters - of this string. - - \note The behavior is undefined if \a len is negative or greater than size(). - - \sa endsWith(), left(), right(), mid(), chop(), truncate() -*/ - -/*! - \since 4.4 - - Returns a substring reference to \a n characters of this string, - starting at the specified \a position. - - If the \a position exceeds the length of the string, a null - reference is returned. - - If there are less than \a n characters available in the string, - starting at the given \a position, or if \a n is -1 (default), the - function returns all characters from the specified \a position - onwards. - - Example: - - \snippet qstring/main.cpp midRef - - \sa mid(), leftRef(), rightRef() -*/ -QStringRef QString::midRef(int position, int n) const -{ - return QStringRef(this).mid(position, n); -} - -/*! - \fn void QStringRef::truncate(int position) - \since 5.6 - - Truncates the string at the given \a position index. - - If the specified \a position index is beyond the end of the - string, nothing happens. - - If \a position is negative, it is equivalent to passing zero. - - \sa QString::truncate() -*/ - -/*! - \fn void QStringRef::chop(int n) - \since 5.8 - - Removes \a n characters from the end of the string. - - If \a n is greater than or equal to size(), the result is an - empty string; if \a n is negative, it is equivalent to passing zero. - - \sa QString::chop(), truncate() -*/ - -#if QT_STRINGVIEW_LEVEL < 2 -/*! - \since 4.8 - - Returns the index position of the first occurrence of the string \a - str in this string reference, searching forward from index position - \a from. Returns -1 if \a str is not found. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - If \a from is -1, the search starts at the last character; if it is - -2, at the next to last character and so on. - - \sa QString::indexOf(), lastIndexOf(), contains(), count() -*/ -int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs)); -} -#endif // QT_STRINGVIEW_LEVEL < 2 - -/*! - \fn int QStringRef::indexOf(QStringView str, int from, Qt::CaseSensitivity cs) const - \since 5.14 - \overload indexOf() - - Returns the index position of the first occurrence of the string view \a str - in this string reference, searching forward from index position \a from. - Returns -1 if \a str is not found. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - If \a from is -1, the search starts at the last character; if it is - -2, at the next to last character and so on. - - \sa QString::indexOf(), QStringView::indexOf(), lastIndexOf(), contains(), count() -*/ - -/*! - \since 4.8 - \overload indexOf() - - Returns the index position of the first occurrence of the - character \a ch in the string reference, searching forward from - index position \a from. Returns -1 if \a ch could not be found. - - \sa QString::indexOf(), lastIndexOf(), contains(), count() -*/ -int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(qFindChar(QStringView(unicode(), length()), ch, from, cs)); -} - -/*! - \since 4.8 - - Returns the index position of the first occurrence of the string \a - str in this string reference, searching forward from index position - \a from. Returns -1 if \a str is not found. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - If \a from is -1, the search starts at the last character; if it is - -2, at the next to last character and so on. - - \sa QString::indexOf(), lastIndexOf(), contains(), count() -*/ -int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::findString(QStringView(unicode(), size()), from, str, cs)); -} - -#if QT_STRINGVIEW_LEVEL < 2 -/*! - \since 4.8 - - \overload indexOf() - - Returns the index position of the first occurrence of the string - reference \a str in this string reference, searching forward from - index position \a from. Returns -1 if \a str is not found. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - \sa QString::indexOf(), lastIndexOf(), contains(), count() -*/ -int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::findString(QStringView(unicode(), size()), from, QStringView(str.unicode(), str.size()), cs)); -} -#endif // QT_STRINGVIEW_LEVEL < 2 - -/*! - \since 4.8 - - Returns the index position of the last occurrence of the string \a - str in this string reference, searching backward from index position - \a from. If \a from is -1 (default), the search starts at the last - character; if \a from is -2, at the next to last character and so - on. Returns -1 if \a str is not found. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - \sa QString::lastIndexOf(), indexOf(), contains(), count() -*/ -int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::lastIndexOf(*this, from, str, cs)); -} - -/*! - \since 4.8 - \overload lastIndexOf() - - Returns the index position of the last occurrence of the character - \a ch, searching backward from position \a from. - - \sa QString::lastIndexOf(), indexOf(), contains(), count() -*/ -int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(qLastIndexOf(*this, ch, from, cs)); -} - -/*! - \since 4.8 - \overload lastIndexOf() - - Returns the index position of the last occurrence of the string \a - str in this string reference, searching backward from index position - \a from. If \a from is -1 (default), the search starts at the last - character; if \a from is -2, at the next to last character and so - on. Returns -1 if \a str is not found. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - \sa QString::lastIndexOf(), indexOf(), contains(), count() -*/ -int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::lastIndexOf(*this, from, str, cs)); -} - -/*! - \since 4.8 - \overload lastIndexOf() - - Returns the index position of the last occurrence of the string - reference \a str in this string reference, searching backward from - index position \a from. If \a from is -1 (default), the search - starts at the last character; if \a from is -2, at the next to last - character and so on. Returns -1 if \a str is not found. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - \sa QString::lastIndexOf(), indexOf(), contains(), count() -*/ -int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::lastIndexOf(*this, from, str, cs)); -} - -/*! - \fn int QStringRef::lastIndexOf(QStringView str, int from, Qt::CaseSensitivity cs) const - \since 5.14 - \overload lastIndexOf() - - Returns the index position of the last occurrence of the string view \a - str in this string, searching backward from index position \a - from. If \a from is -1 (default), the search starts at the last - character; if \a from is -2, at the next to last character and so - on. Returns -1 if \a str is not found. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - \sa indexOf(), contains(), count() -*/ - -/*! - \since 4.8 - Returns the number of (potentially overlapping) occurrences of - the string \a str in this string reference. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - - \sa QString::count(), contains(), indexOf() -*/ -int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); -} - -/*! - \since 4.8 - \overload count() - - Returns the number of occurrences of the character \a ch in the - string reference. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - - \sa QString::count(), contains(), indexOf() -*/ -int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::count(QStringView(unicode(), size()), ch, cs)); -} - -/*! - \since 4.8 - \overload count() - - Returns the number of (potentially overlapping) occurrences of the - string reference \a str in this string reference. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - - \sa QString::count(), contains(), indexOf() -*/ -int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const -{ - // ### Qt6: qsizetype - return int(QtPrivate::count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); -} - -/*! - \since 5.9 - - Returns \c true if the string is read right to left. - - \sa QString::isRightToLeft() -*/ -bool QStringRef::isRightToLeft() const -{ - return QtPrivate::isRightToLeft(QStringView(unicode(), size())); -} - /*! \since 5.11 \internal @@ -10849,193 +9568,6 @@ bool QtPrivate::isRightToLeft(QStringView string) noexcept return false; } -/*! - \since 4.8 - - Returns \c true if the string reference starts with \a str; otherwise - returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - - \sa QString::startsWith(), endsWith() -*/ -bool QStringRef::startsWith(const QString &str, Qt::CaseSensitivity cs) const -{ - return qt_starts_with(*this, str, cs); -} - -/*! - \since 4.8 - \overload startsWith() - \sa QString::startsWith(), endsWith() -*/ -bool QStringRef::startsWith(QLatin1String str, Qt::CaseSensitivity cs) const -{ - return qt_starts_with(*this, str, cs); -} - -/*! - \fn bool QStringRef::startsWith(QStringView str, Qt::CaseSensitivity cs) const - \since 5.10 - \overload startsWith() - \sa QString::startsWith(), endsWith() -*/ - -/*! - \since 4.8 - \overload startsWith() - \sa QString::startsWith(), endsWith() -*/ -bool QStringRef::startsWith(const QStringRef &str, Qt::CaseSensitivity cs) const -{ - return qt_starts_with(*this, str, cs); -} - -/*! - \since 4.8 - \overload startsWith() - - Returns \c true if the string reference starts with \a ch; otherwise - returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - \sa QString::startsWith(), endsWith() -*/ -bool QStringRef::startsWith(QChar ch, Qt::CaseSensitivity cs) const -{ - return qt_starts_with(*this, ch, cs); -} - -/*! - \since 4.8 - Returns \c true if the string reference ends with \a str; otherwise - returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - \sa QString::endsWith(), startsWith() -*/ -bool QStringRef::endsWith(const QString &str, Qt::CaseSensitivity cs) const -{ - return qt_ends_with(*this, str, cs); -} - -/*! - \since 4.8 - \overload endsWith() - - Returns \c true if the string reference ends with \a ch; otherwise - returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is case - sensitive; otherwise the search is case insensitive. - - \sa QString::endsWith(), endsWith() -*/ -bool QStringRef::endsWith(QChar ch, Qt::CaseSensitivity cs) const -{ - return qt_ends_with(*this, ch, cs); -} - -/*! - \since 4.8 - \overload endsWith() - \sa QString::endsWith(), endsWith() -*/ -bool QStringRef::endsWith(QLatin1String str, Qt::CaseSensitivity cs) const -{ - return qt_ends_with(*this, str, cs); -} - -/*! - \fn bool QStringRef::endsWith(QStringView str, Qt::CaseSensitivity cs) const - \since 5.10 - \overload endsWith() - \sa QString::endsWith(), startsWith() -*/ - -/*! - \since 4.8 - \overload endsWith() - \sa QString::endsWith(), endsWith() -*/ -bool QStringRef::endsWith(const QStringRef &str, Qt::CaseSensitivity cs) const -{ - return qt_ends_with(*this, str, cs); -} - -#if QT_STRINGVIEW_LEVEL < 2 -/*! \fn bool QStringRef::contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - - \since 4.8 - Returns \c true if this string reference contains an occurrence of - the string \a str; otherwise returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - - \sa indexOf(), count() -*/ -#endif // QT_STRINGVIEW_LEVEL < 2 - -/*! \fn bool QStringRef::contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - - \overload contains() - \since 4.8 - - Returns \c true if this string contains an occurrence of the - character \a ch; otherwise returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - -*/ - -#if QT_STRINGVIEW_LEVEL < 2 -/*! \fn bool QStringRef::contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \overload contains() - \since 4.8 - - Returns \c true if this string reference contains an occurrence of - the string reference \a str; otherwise returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - - \sa indexOf(), count() -*/ -#endif // QT_STRINGVIEW_LEVEL < 2 - -/*! \fn bool QStringRef::contains(QLatin1String str, Qt::CaseSensitivity cs) const - \since 4.8 - \overload contains() - - Returns \c true if this string reference contains an occurrence of - the string \a str; otherwise returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - - \sa indexOf(), count() -*/ - -/*! \fn bool QStringRef::contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \since 5.14 - \overload contains() - - Returns \c true if this string reference contains an occurrence of - the string view \a str; otherwise returns \c false. - - If \a cs is Qt::CaseSensitive (default), the search is - case sensitive; otherwise the search is case insensitive. - - \sa indexOf(), count() -*/ - qsizetype QtPrivate::count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) noexcept { qsizetype num = 0; @@ -11501,356 +10033,6 @@ qsizetype QtPrivate::lastIndexOf(QLatin1String haystack, qsizetype from, QLatin1 } /*! - \since 4.8 - - Returns a Latin-1 representation of the string as a QByteArray. - - The returned byte array is undefined if the string contains non-Latin1 - characters. Those characters may be suppressed or replaced with a - question mark. - - \sa toUtf8(), toLocal8Bit(), QStringEncoder -*/ -QByteArray QStringRef::toLatin1() const -{ - return qt_convert_to_latin1(*this); -} - -/*! - \since 4.8 - - Returns the local 8-bit representation of the string as a - QByteArray. The returned byte array is undefined if the string - contains characters not supported by the local 8-bit encoding. - - On Unix systems this is equivalen to toUtf8(), on Windows the systems - current code page is being used. - - If this string contains any characters that cannot be encoded in the - locale, the returned byte array is undefined. Those characters may be - suppressed or replaced by another. - - \sa toLatin1(), toUtf8(), QStringEncoder -*/ -QByteArray QStringRef::toLocal8Bit() const -{ - return qt_convert_to_local_8bit(*this); -} - -/*! - \since 4.8 - - Returns a UTF-8 representation of the string as a QByteArray. - - UTF-8 is a Unicode codec and can represent all characters in a Unicode - string like QString. - - \sa toLatin1(), toLocal8Bit(), QStringEncoder -*/ -QByteArray QStringRef::toUtf8() const -{ - return qt_convert_to_utf8(*this); -} - -/*! - \since 4.8 - - Returns a UCS-4/UTF-32 representation of the string as a QList<uint>. - - UCS-4 is a Unicode codec and therefore it is lossless. All characters from - this string will be encoded in UCS-4. Any invalid sequence of code units in - this string is replaced by the Unicode's replacement character - (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). - - The returned list is not \\0'-terminated. - - \sa toUtf8(), toLatin1(), toLocal8Bit(), QStringEncoder -*/ -QList<uint> QStringRef::toUcs4() const -{ - return qt_convert_to_ucs4(*this); -} - -/*! - Returns a string that has whitespace removed from the start and - the end. - - Whitespace means any character for which QChar::isSpace() returns - \c true. This includes the ASCII characters '\\t', '\\n', '\\v', - '\\f', '\\r', and ' '. - - Unlike QString::simplified(), trimmed() leaves internal whitespace alone. - - \since 5.1 - - \sa QString::trimmed() -*/ -QStringRef QStringRef::trimmed() const -{ - const QChar *begin = cbegin(); - const QChar *end = cend(); - QStringAlgorithms<const QStringRef>::trimmed_helper_positions(begin, end); - if (begin == cbegin() && end == cend()) - return *this; - int position = m_position + (begin - cbegin()); - return QStringRef(m_string, position, end - begin); -} - -/*! - Returns the string converted to a \c{long long} using base \a - base, which is 10 by default and must be between 2 and 36, or 0. - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - If \a base is 0, the C language convention is used: If the string - begins with "0x", base 16 is used; if the string begins with "0", - base 8 is used; otherwise, base 10 is used. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toLongLong() - - \sa QString::toLongLong() - - \since 5.1 -*/ - -qint64 QStringRef::toLongLong(bool *ok, int base) const -{ - return QString::toIntegral_helper<qint64>(*this, ok, base); -} - -/*! - Returns the string converted to an \c{unsigned long long} using base \a - base, which is 10 by default and must be between 2 and 36, or 0. - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - If \a base is 0, the C language convention is used: If the string - begins with "0x", base 16 is used; if the string begins with "0", - base 8 is used; otherwise, base 10 is used. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toULongLong() - - \sa QString::toULongLong() - - \since 5.1 -*/ - -quint64 QStringRef::toULongLong(bool *ok, int base) const -{ - return QString::toIntegral_helper<quint64>(*this, ok, base); -} - -/*! - \fn long QStringRef::toLong(bool *ok, int base) const - - Returns the string converted to a \c long using base \a - base, which is 10 by default and must be between 2 and 36, or 0. - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - If \a base is 0, the C language convention is used: If the string - begins with "0x", base 16 is used; if the string begins with "0", - base 8 is used; otherwise, base 10 is used. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toLong() - - \sa QString::toLong() - - \since 5.1 -*/ - -long QStringRef::toLong(bool *ok, int base) const -{ - return QString::toIntegral_helper<long>(*this, ok, base); -} - -/*! - \fn ulong QStringRef::toULong(bool *ok, int base) const - - Returns the string converted to an \c{unsigned long} using base \a - base, which is 10 by default and must be between 2 and 36, or 0. - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - If \a base is 0, the C language convention is used: If the string - begins with "0x", base 16 is used; if the string begins with "0", - base 8 is used; otherwise, base 10 is used. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toULongLong() - - \sa QString::toULong() - - \since 5.1 -*/ - -ulong QStringRef::toULong(bool *ok, int base) const -{ - return QString::toIntegral_helper<ulong>(*this, ok, base); -} - - -/*! - Returns the string converted to an \c int using base \a - base, which is 10 by default and must be between 2 and 36, or 0. - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - If \a base is 0, the C language convention is used: If the string - begins with "0x", base 16 is used; if the string begins with "0", - base 8 is used; otherwise, base 10 is used. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toInt() - - \sa QString::toInt() - - \since 5.1 -*/ - -int QStringRef::toInt(bool *ok, int base) const -{ - return QString::toIntegral_helper<int>(*this, ok, base); -} - -/*! - Returns the string converted to an \c{unsigned int} using base \a - base, which is 10 by default and must be between 2 and 36, or 0. - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - If \a base is 0, the C language convention is used: If the string - begins with "0x", base 16 is used; if the string begins with "0", - base 8 is used; otherwise, base 10 is used. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toUInt() - - \sa QString::toUInt() - - \since 5.1 -*/ - -uint QStringRef::toUInt(bool *ok, int base) const -{ - return QString::toIntegral_helper<uint>(*this, ok, base); -} - -/*! - Returns the string converted to a \c short using base \a - base, which is 10 by default and must be between 2 and 36, or 0. - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - If \a base is 0, the C language convention is used: If the string - begins with "0x", base 16 is used; if the string begins with "0", - base 8 is used; otherwise, base 10 is used. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toShort() - - \sa QString::toShort() - - \since 5.1 -*/ - -short QStringRef::toShort(bool *ok, int base) const -{ - return QString::toIntegral_helper<short>(*this, ok, base); -} - -/*! - Returns the string converted to an \c{unsigned short} using base \a - base, which is 10 by default and must be between 2 and 36, or 0. - Returns 0 if the conversion fails. - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - If \a base is 0, the C language convention is used: If the string - begins with "0x", base 16 is used; if the string begins with "0", - base 8 is used; otherwise, base 10 is used. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toUShort() - - \sa QString::toUShort() - - \since 5.1 -*/ - -ushort QStringRef::toUShort(bool *ok, int base) const -{ - return QString::toIntegral_helper<ushort>(*this, ok, base); -} - - -/*! - Returns the string converted to a \c double value. - - Returns an infinity if the conversion overflows or 0.0 if the - conversion fails for other reasons (e.g. underflow). - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toDouble() - - For historic reasons, this function does not handle - thousands group separators. If you need to convert such numbers, - use QLocale::toDouble(). - - \sa QString::toDouble() - - \since 5.1 -*/ - -double QStringRef::toDouble(bool *ok) const -{ - return QLocaleData::c()->stringToDouble(*this, ok, QLocale::RejectGroupSeparator); -} - -/*! - Returns the string converted to a \c float value. - - Returns an infinity if the conversion overflows or 0.0 if the - conversion fails for other reasons (e.g. underflow). - - If \a ok is not \nullptr, failure is reported by setting *\a{ok} - to \c false, and success by setting *\a{ok} to \c true. - - The string conversion will always happen in the 'C' locale. For locale - dependent conversion use QLocale::toFloat() - - \sa QString::toFloat() - - \since 5.1 -*/ - -float QStringRef::toFloat(bool *ok) const -{ - return QLocaleData::convertDoubleToFloat(toDouble(ok), ok); -} - -/*! \since 5.0 Converts a plain text string to an HTML string with diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 131d79a70c..df1fb64f29 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -76,7 +76,6 @@ class QRegularExpression; class QRegularExpressionMatch; class QString; class QStringList; -class QStringRef; namespace QtPrivate { template <bool...B> class BoolList; @@ -449,10 +448,6 @@ public: { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return first(size() - n); } - Q_REQUIRED_RESULT QStringRef leftRef(int n) const; - Q_REQUIRED_RESULT QStringRef rightRef(int n) const; - Q_REQUIRED_RESULT QStringRef midRef(int position, int n = -1) const; - #if QT_STRINGVIEW_LEVEL < 2 bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif @@ -570,20 +565,12 @@ public: QStringList split(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; Q_REQUIRED_RESULT - QList<QStringRef> splitRef(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, - Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - Q_REQUIRED_RESULT QStringList split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - Q_REQUIRED_RESULT - QList<QStringRef> splitRef(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, - Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #ifndef QT_NO_REGULAREXPRESSION Q_REQUIRED_RESULT QStringList split(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const; - Q_REQUIRED_RESULT - QList<QStringRef> splitRef(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const; #endif template <typename Needle, typename...Flags> @@ -820,13 +807,6 @@ public: friend inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QString &s2); friend inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QString &s2); friend inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QString &s2); - - friend inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QStringRef &s2); - friend inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QStringRef &s2); - friend inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QStringRef &s2); - friend inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QStringRef &s2); - friend inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QStringRef &s2); - friend inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2); #endif typedef QChar *iterator; @@ -910,9 +890,6 @@ private: friend inline bool operator==(QChar, const QString &) noexcept; friend inline bool operator< (QChar, const QString &) noexcept; friend inline bool operator> (QChar, const QString &) noexcept; - friend inline bool operator==(QChar, const QStringRef &) noexcept; - friend inline bool operator< (QChar, const QStringRef &) noexcept; - friend inline bool operator> (QChar, const QStringRef &) noexcept; friend inline bool operator==(QChar, QLatin1String) noexcept; friend inline bool operator< (QChar, QLatin1String) noexcept; friend inline bool operator> (QChar, QLatin1String) noexcept; @@ -950,7 +927,6 @@ private: static qlonglong toIntegral_helper(QStringView string, bool *ok, int base); static qulonglong toIntegral_helper(QStringView string, bool *ok, uint base); void replace_helper(size_t *indices, qsizetype nIndices, qsizetype blen, const QChar *after, qsizetype alen); - friend class QStringRef; friend class QStringView; friend class QByteArray; friend class QCollator; @@ -1340,251 +1316,8 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QString &); Q_DECLARE_SHARED(QString) Q_DECLARE_OPERATORS_FOR_FLAGS(QString::SectionFlags) - -class Q_CORE_EXPORT QStringRef { - const QString *m_string; - int m_position; - int m_size; -public: - typedef QString::size_type size_type; - typedef QString::value_type value_type; - typedef const QChar *const_iterator; - typedef std::reverse_iterator<const_iterator> const_reverse_iterator; - typedef QString::const_pointer const_pointer; - typedef QString::const_reference const_reference; - - // ### Qt 6: make this constructor constexpr, after the destructor is made trivial - inline QStringRef() : m_string(nullptr), m_position(0), m_size(0) {} - inline QStringRef(const QString *string, int position, int size); - inline QStringRef(const QString *string); - - inline const QString *string() const { return m_string; } - inline int position() const { return m_position; } - inline int size() const { return m_size; } - inline int count() const { return m_size; } - inline int length() const { return m_size; } - -#if QT_STRINGVIEW_LEVEL < 2 - int indexOf(const QString &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int indexOf(const QStringRef &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#endif - Q_REQUIRED_RESULT int indexOf(QStringView s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsizetype - int indexOf(QChar ch, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int indexOf(QLatin1String str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#if QT_STRINGVIEW_LEVEL < 2 - int lastIndexOf(const QStringRef &str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int lastIndexOf(const QString &str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#endif - int lastIndexOf(QChar ch, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int lastIndexOf(QLatin1String str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - Q_REQUIRED_RESULT int lastIndexOf(QStringView s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsizetype - -#if QT_STRINGVIEW_LEVEL < 2 - inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline bool contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#endif - inline bool contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline bool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - inline bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - - int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int count(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - - Q_REQUIRED_RESULT - QList<QStringRef> split(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, - Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - Q_REQUIRED_RESULT - QList<QStringRef> split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, - Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - - Q_REQUIRED_RESULT QStringRef left(int n) const; - Q_REQUIRED_RESULT QStringRef right(int n) const; - Q_REQUIRED_RESULT QStringRef mid(int pos, int n = -1) const; - Q_REQUIRED_RESULT QStringRef chopped(int n) const - { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return left(size() - n); } - - void truncate(int pos) noexcept { m_size = qBound(0, pos, m_size); } - void chop(int n) noexcept - { - if (n >= m_size) - m_size = 0; - else if (n > 0) - m_size -= n; - } - - bool isRightToLeft() const; - - Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::startsWith(*this, s, cs); } - bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#if QT_STRINGVIEW_LEVEL < 2 - bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - bool startsWith(const QStringRef &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#endif - - Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::endsWith(*this, s, cs); } - bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#if QT_STRINGVIEW_LEVEL < 2 - bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - bool endsWith(const QStringRef &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -#endif - - inline QStringRef &operator=(const QString *string); - - inline const QChar *unicode() const - { - if (!m_string) - return reinterpret_cast<const QChar *>(&QString::_empty); - return m_string->unicode() + m_position; - } - inline const QChar *data() const { return unicode(); } - inline const QChar *constData() const { return unicode(); } - - inline const_iterator begin() const { return unicode(); } - inline const_iterator cbegin() const { return unicode(); } - inline const_iterator constBegin() const { return unicode(); } - inline const_iterator end() const { return unicode() + size(); } - inline const_iterator cend() const { return unicode() + size(); } - inline const_iterator constEnd() const { return unicode() + size(); } - inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } - inline const_reverse_iterator crbegin() const { return rbegin(); } - inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } - inline const_reverse_iterator crend() const { return rend(); } - - Q_REQUIRED_RESULT QByteArray toLatin1() const; - Q_REQUIRED_RESULT QByteArray toUtf8() const; - Q_REQUIRED_RESULT QByteArray toLocal8Bit() const; - Q_REQUIRED_RESULT QList<uint> toUcs4() const; - - inline void clear() { m_string = nullptr; m_position = m_size = 0; } - QString toString() const; - inline bool isEmpty() const { return m_size == 0; } - inline bool isNull() const { return m_string == nullptr || m_string->isNull(); } - - QStringRef appendTo(QString *string) const; - - inline const QChar at(int i) const - { Q_ASSERT(uint(i) < uint(size())); return m_string->at(i + m_position); } - QChar operator[](int i) const { return at(i); } - Q_REQUIRED_RESULT QChar front() const { return at(0); } - Q_REQUIRED_RESULT QChar back() const { return at(size() - 1); } - -#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) - // ASCII compatibility - inline QT_ASCII_CAST_WARN bool operator==(const char *s) const; - inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const; - inline QT_ASCII_CAST_WARN bool operator<(const char *s) const; - inline QT_ASCII_CAST_WARN bool operator<=(const char *s) const; - inline QT_ASCII_CAST_WARN bool operator>(const char *s) const; - inline QT_ASCII_CAST_WARN bool operator>=(const char *s) const; -#endif - - int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - int compare(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } - int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; -#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) - int compare(const QByteArray &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - { return QString::compare_helper(unicode(), size(), s.data(), qstrnlen(s.data(), s.size()), cs); } -#endif - static int compare(const QStringRef &s1, const QString &s2, - Qt::CaseSensitivity = Qt::CaseSensitive) noexcept; - static int compare(const QStringRef &s1, const QStringRef &s2, - Qt::CaseSensitivity = Qt::CaseSensitive) noexcept; - static int compare(const QStringRef &s1, QLatin1String s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - - int localeAwareCompare(const QString &s) const; - int localeAwareCompare(const QStringRef &s) const; - static int localeAwareCompare(const QStringRef &s1, const QString &s2); - static int localeAwareCompare(const QStringRef &s1, const QStringRef &s2); - - Q_REQUIRED_RESULT QStringRef trimmed() const; - short toShort(bool *ok = nullptr, int base = 10) const; - ushort toUShort(bool *ok = nullptr, int base = 10) const; - int toInt(bool *ok = nullptr, int base = 10) const; - uint toUInt(bool *ok = nullptr, int base = 10) const; - long toLong(bool *ok = nullptr, int base = 10) const; - ulong toULong(bool *ok = nullptr, int base = 10) const; - qlonglong toLongLong(bool *ok = nullptr, int base = 10) const; - qulonglong toULongLong(bool *ok = nullptr, int base = 10) const; - float toFloat(bool *ok = nullptr) const; - double toDouble(bool *ok = nullptr) const; -}; -Q_DECLARE_TYPEINFO(QStringRef, Q_PRIMITIVE_TYPE); - -inline QStringRef &QStringRef::operator=(const QString *aString) -{ m_string = aString; m_position = 0; m_size = aString?aString->size():0; return *this; } - -inline QStringRef::QStringRef(const QString *aString, int aPosition, int aSize) - :m_string(aString), m_position(aPosition), m_size(aSize){} - -inline QStringRef::QStringRef(const QString *aString) - :m_string(aString), m_position(0), m_size(aString?aString->size() : 0){} - -// QStringRef <> QStringRef -Q_CORE_EXPORT bool operator==(const QStringRef &s1, const QStringRef &s2) noexcept; -inline bool operator!=(const QStringRef &s1, const QStringRef &s2) noexcept -{ return !(s1 == s2); } -Q_CORE_EXPORT bool operator<(const QStringRef &s1, const QStringRef &s2) noexcept; -inline bool operator>(const QStringRef &s1, const QStringRef &s2) noexcept -{ return s2 < s1; } -inline bool operator<=(const QStringRef &s1, const QStringRef &s2) noexcept -{ return !(s1 > s2); } -inline bool operator>=(const QStringRef &s1, const QStringRef &s2) noexcept -{ return !(s1 < s2); } - -// QString <> QStringRef -Q_CORE_EXPORT bool operator==(const QString &lhs, const QStringRef &rhs) noexcept; -inline bool operator!=(const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) != 0; } -inline bool operator< (const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) < 0; } -inline bool operator> (const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) > 0; } -inline bool operator<=(const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) <= 0; } -inline bool operator>=(const QString &lhs, const QStringRef &rhs) noexcept { return lhs.compare(rhs) >= 0; } - -inline bool operator==(const QStringRef &lhs, const QString &rhs) noexcept { return rhs == lhs; } -inline bool operator!=(const QStringRef &lhs, const QString &rhs) noexcept { return rhs != lhs; } -inline bool operator< (const QStringRef &lhs, const QString &rhs) noexcept { return rhs > lhs; } -inline bool operator> (const QStringRef &lhs, const QString &rhs) noexcept { return rhs < lhs; } -inline bool operator<=(const QStringRef &lhs, const QString &rhs) noexcept { return rhs >= lhs; } -inline bool operator>=(const QStringRef &lhs, const QString &rhs) noexcept { return rhs <= lhs; } - inline int QString::compare(QStringView s, Qt::CaseSensitivity cs) const noexcept { return -s.compare(*this, cs); } -inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const noexcept -{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const noexcept -{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const noexcept -{ return QString::compare_helper(constData(), length(), s, cs); } -inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) noexcept -{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) noexcept -{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) noexcept -{ return QString::compare_helper(s1.constData(), s1.length(), s2, cs); } - -// QLatin1String <> QStringRef -Q_CORE_EXPORT bool operator==(QLatin1String lhs, const QStringRef &rhs) noexcept; -inline bool operator!=(QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) != 0; } -inline bool operator< (QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) > 0; } -inline bool operator> (QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) < 0; } -inline bool operator<=(QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) >= 0; } -inline bool operator>=(QLatin1String lhs, const QStringRef &rhs) noexcept { return rhs.compare(lhs) <= 0; } - -inline bool operator==(const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs == lhs; } -inline bool operator!=(const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs != lhs; } -inline bool operator< (const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs > lhs; } -inline bool operator> (const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs < lhs; } -inline bool operator<=(const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs >= lhs; } -inline bool operator>=(const QStringRef &lhs, QLatin1String rhs) noexcept { return rhs <= lhs; } // QChar <> QString inline bool operator==(QChar lhs, const QString &rhs) noexcept @@ -1605,25 +1338,6 @@ inline bool operator> (const QString &lhs, QChar rhs) noexcept { return rhs < inline bool operator<=(const QString &lhs, QChar rhs) noexcept { return !(rhs < lhs); } inline bool operator>=(const QString &lhs, QChar rhs) noexcept { return !(rhs > lhs); } -// QChar <> QStringRef -inline bool operator==(QChar lhs, const QStringRef &rhs) noexcept -{ return rhs.size() == 1 && lhs == rhs.front(); } -inline bool operator< (QChar lhs, const QStringRef &rhs) noexcept -{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; } -inline bool operator> (QChar lhs, const QStringRef &rhs) noexcept -{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; } - -inline bool operator!=(QChar lhs, const QStringRef &rhs) noexcept { return !(lhs == rhs); } -inline bool operator<=(QChar lhs, const QStringRef &rhs) noexcept { return !(lhs > rhs); } -inline bool operator>=(QChar lhs, const QStringRef &rhs) noexcept { return !(lhs < rhs); } - -inline bool operator==(const QStringRef &lhs, QChar rhs) noexcept { return rhs == lhs; } -inline bool operator!=(const QStringRef &lhs, QChar rhs) noexcept { return !(rhs == lhs); } -inline bool operator< (const QStringRef &lhs, QChar rhs) noexcept { return rhs > lhs; } -inline bool operator> (const QStringRef &lhs, QChar rhs) noexcept { return rhs < lhs; } -inline bool operator<=(const QStringRef &lhs, QChar rhs) noexcept { return !(rhs < lhs); } -inline bool operator>=(const QStringRef &lhs, QChar rhs) noexcept { return !(rhs > lhs); } - // QChar <> QLatin1String inline bool operator==(QChar lhs, QLatin1String rhs) noexcept { return rhs.size() == 1 && lhs == rhs.front(); } @@ -1681,92 +1395,10 @@ inline bool operator<=(QLatin1String lhs, QStringView rhs) noexcept { return QtP inline bool operator> (QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) > 0; } inline bool operator>=(QLatin1String lhs, QStringView rhs) noexcept { return QtPrivate::compareStrings(lhs, rhs) >= 0; } -#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) -// QStringRef <> QByteArray -inline QT_ASCII_CAST_WARN bool operator==(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) == 0; } -inline QT_ASCII_CAST_WARN bool operator!=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) != 0; } -inline QT_ASCII_CAST_WARN bool operator< (const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) < 0; } -inline QT_ASCII_CAST_WARN bool operator> (const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) > 0; } -inline QT_ASCII_CAST_WARN bool operator<=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) <= 0; } -inline QT_ASCII_CAST_WARN bool operator>=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) >= 0; } - -inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) == 0; } -inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) != 0; } -inline QT_ASCII_CAST_WARN bool operator< (const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) > 0; } -inline QT_ASCII_CAST_WARN bool operator> (const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) < 0; } -inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) >= 0; } -inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) <= 0; } - -// QStringRef <> const char * -inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const -{ return QString::compare_helper(constData(), size(), s, -1) == 0; } -inline QT_ASCII_CAST_WARN bool QStringRef::operator!=(const char *s) const -{ return QString::compare_helper(constData(), size(), s, -1) != 0; } -inline QT_ASCII_CAST_WARN bool QStringRef::operator<(const char *s) const -{ return QString::compare_helper(constData(), size(), s, -1) < 0; } -inline QT_ASCII_CAST_WARN bool QStringRef::operator<=(const char *s) const -{ return QString::compare_helper(constData(), size(), s, -1) <= 0; } -inline QT_ASCII_CAST_WARN bool QStringRef::operator>(const char *s) const -{ return QString::compare_helper(constData(), size(), s, -1) > 0; } -inline QT_ASCII_CAST_WARN bool QStringRef::operator>=(const char *s) const -{ return QString::compare_helper(constData(), size(), s, -1) >= 0; } - -inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QStringRef &s2) -{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) == 0; } -inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QStringRef &s2) -{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) != 0; } -inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QStringRef &s2) -{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) > 0; } -inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QStringRef &s2) -{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; } -inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QStringRef &s2) -{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) < 0; } -inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2) -{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; } -#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) - inline int QString::localeAwareCompare(QStringView s) const { return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); } inline int QString::localeAwareCompare(QStringView s1, QStringView s2) { return localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); } -inline int QStringRef::localeAwareCompare(const QString &s) const -{ return QString::localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); } -inline int QStringRef::localeAwareCompare(const QStringRef &s) const -{ return QString::localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); } -inline int QStringRef::localeAwareCompare(const QStringRef &s1, const QString &s2) -{ return QString::localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); } -inline int QStringRef::localeAwareCompare(const QStringRef &s1, const QStringRef &s2) -{ return QString::localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); } - -#if QT_STRINGVIEW_LEVEL < 2 -inline bool QStringRef::contains(const QString &s, Qt::CaseSensitivity cs) const -{ return indexOf(s, 0, cs) != -1; } -inline bool QStringRef::contains(const QStringRef &s, Qt::CaseSensitivity cs) const -{ return indexOf(s, 0, cs) != -1; } -#endif -inline bool QStringRef::contains(QLatin1String s, Qt::CaseSensitivity cs) const -{ return indexOf(s, 0, cs) != -1; } -inline bool QStringRef::contains(QChar c, Qt::CaseSensitivity cs) const -{ return indexOf(c, 0, cs) != -1; } -inline bool QStringRef::contains(QStringView s, Qt::CaseSensitivity cs) const noexcept -{ return indexOf(s, 0, cs) != -1; } - -#if !defined(QT_USE_FAST_OPERATOR_PLUS) && !defined(QT_USE_QSTRINGBUILDER) -inline QString operator+(const QString &s1, const QStringRef &s2) -{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; } -inline QString operator+(const QStringRef &s1, const QString &s2) -{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; } -inline QString operator+(const QStringRef &s1, QLatin1String s2) -{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; } -inline QString operator+(QLatin1String s1, const QStringRef &s2) -{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; } -inline QString operator+(const QStringRef &s1, const QStringRef &s2) -{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; } -inline QString operator+(const QStringRef &s1, QChar s2) -{ QString t; t.reserve(s1.size() + 1); t += s1; t += s2; return t; } -inline QString operator+(QChar s1, const QStringRef &s2) -{ QString t; t.reserve(1 + s2.size()); t += s1; t += s2; return t; } -#endif // !(QT_USE_FAST_OPERATOR_PLUS || QT_USE_QSTRINGBUILDER) namespace QtPrivate { // used by qPrintable() and qUtf8Printable() macros diff --git a/src/corelib/text/qstringbuilder.cpp b/src/corelib/text/qstringbuilder.cpp index 4e47ba0922..3016392e45 100644 --- a/src/corelib/text/qstringbuilder.cpp +++ b/src/corelib/text/qstringbuilder.cpp @@ -72,7 +72,7 @@ QT_BEGIN_NAMESPACE For building QStrings: \list - \li QString, QStringRef, (since 5.10:) QStringView + \li QString, (since 5.10:) QStringView \li QChar, QLatin1Char, (since 5.10:) \c char16_t, \li QLatin1String, \li (since 5.10:) \c{const char16_t[]} (\c{u"foo"}), @@ -107,7 +107,7 @@ QT_BEGIN_NAMESPACE takes a QString parameter. This function is usable with arguments of type \c QString, - \c QLatin1String, \c QStringRef, + \c QLatin1String, \c QChar, \c QLatin1Char, and \c char. */ diff --git a/src/corelib/text/qstringbuilder.h b/src/corelib/text/qstringbuilder.h index da4277f9a8..e5a3a59eb2 100644 --- a/src/corelib/text/qstringbuilder.h +++ b/src/corelib/text/qstringbuilder.h @@ -266,21 +266,6 @@ template <> struct QConcatenable<QString> : private QAbstractConcatenable } }; -template <> struct QConcatenable<QStringRef> : private QAbstractConcatenable -{ - typedef QStringRef type; - typedef QString ConvertTo; - enum { ExactSize = true }; - static int size(const QStringRef &a) { return a.size(); } - static inline void appendTo(const QStringRef &a, QChar *&out) - { - const int n = a.size(); - if (n) - memcpy(out, reinterpret_cast<const char*>(a.constData()), sizeof(QChar) * n); - out += n; - } -}; - template <> struct QConcatenable<QStringView> : private QAbstractConcatenable { typedef QStringView type; diff --git a/src/corelib/text/qstringconverter_p.h b/src/corelib/text/qstringconverter_p.h index 3a99a4191a..2130bea6e8 100644 --- a/src/corelib/text/qstringconverter_p.h +++ b/src/corelib/text/qstringconverter_p.h @@ -326,11 +326,11 @@ enum DataEndianness struct QUtf8 { - static QChar *convertToUnicode(QChar *, const char *, qsizetype) noexcept; + Q_CORE_EXPORT static QChar *convertToUnicode(QChar *, const char *, qsizetype) noexcept; static QString convertToUnicode(const char *, qsizetype); Q_CORE_EXPORT static QString convertToUnicode(const char *, qsizetype, QStringConverter::State *); static QChar *convertToUnicode(QChar *out, const char *in, qsizetype length, QStringConverter::State *state); - static QByteArray convertFromUnicode(const QChar *, qsizetype); + Q_CORE_EXPORT static QByteArray convertFromUnicode(const QChar *, qsizetype); Q_CORE_EXPORT static QByteArray convertFromUnicode(const QChar *, qsizetype, QStringConverter::State *); static char *convertFromUnicode(char *out, QStringView in, QStringConverter::State *state); struct ValidUtf8Result { diff --git a/src/corelib/text/qstringtokenizer.h b/src/corelib/text/qstringtokenizer.h index 4db23db57f..333153f5a3 100644 --- a/src/corelib/text/qstringtokenizer.h +++ b/src/corelib/text/qstringtokenizer.h @@ -173,7 +173,6 @@ namespace Tok { template <> struct ViewForImpl<QLatin1String> { using type = QLatin1String; }; template <> struct ViewForImpl<QChar> { using type = QChar; }; template <> struct ViewForImpl<QString> : ViewForImpl<QStringView> {}; - template <> struct ViewForImpl<QStringRef> : ViewForImpl<QStringView> {}; template <> struct ViewForImpl<QLatin1Char> : ViewForImpl<QChar> {}; template <> struct ViewForImpl<char16_t> : ViewForImpl<QChar> {}; template <> struct ViewForImpl<char16_t*> : ViewForImpl<QStringView> {}; diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index a36a98fca4..971d2ffd7a 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE When used as an interface type, QStringView allows a single function to accept a wide variety of UTF-16 string data sources. One function accepting QStringView - thus replaces three function overloads (taking QString, QStringRef, and + thus replaces three function overloads (taking QString and \c{(const QChar*, int)}), while at the same time enabling even more string data sources to be passed to the function, such as \c{u"Hello World"}, a \c char16_t string literal. @@ -105,7 +105,7 @@ QT_BEGIN_NAMESPACE allowed in \c constexpr functions). You can use an indexed loop and/or utf16() in \c constexpr contexts instead. - \sa QString, QStringRef + \sa QString */ /*! @@ -305,16 +305,6 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QStringView::QStringView(const QStringRef &str) - - Constructs a string view on \a str. - - \c{str.data()} must remain valid for the lifetime of this string view object. - - The string view will be null if and only if \c{str.isNull()}. -*/ - -/*! \fn template <typename StdBasicString> QStringView::QStringView(const StdBasicString &str) Constructs a string view on \a str. The length is taken from \c{str.size()}. @@ -496,7 +486,7 @@ QT_BEGIN_NAMESPACE Returns the size of this string view, in UTF-16 code points (that is, surrogate pairs count as two for the purposes of this function, the same - as in QString and QStringRef). + as in QString). \sa empty(), isEmpty(), isNull(), length() */ @@ -918,10 +908,10 @@ QT_BEGIN_NAMESPACE Returns a string-view that references \a{s}' data, but is never null. - This is a faster way to convert a QString or QStringRef to a QStringView, + This is a faster way to convert a QString to a QStringView, if null QStrings can legitimately be treated as empty ones. - \sa QString::isNull(), QStringRef::isNull(), QStringView + \sa QString::isNull(), QStringView */ /*! diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index f2e9f876f9..a59a24f8a5 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -46,9 +46,7 @@ 1. offer QStringView, overload some functions taking QString with QStringView - 2. like 1, but remove all overloads of functions taking QStringRef, - leaving only the function taking QStringView. Do this only where - QStringRef overloads tradionally existed. + 2. Obsolete: QStringRef and its overloads have been removed. 3. like 2, but replace functions taking QString, too. */ @@ -71,7 +69,6 @@ Q_FORWARD_DECLARE_OBJC_CLASS(NSString); QT_BEGIN_NAMESPACE class QString; -class QStringRef; class QStringView; class QRegularExpression; @@ -113,7 +110,6 @@ struct IsContainerCompatibleWithQStringView<T, std::enable_if_t<std::conjunction // These need to be treated specially due to the empty vs null distinction std::negation<std::is_same<std::decay_t<T>, QString>>, - std::negation<std::is_same<std::decay_t<T>, QStringRef>>, // Don't make an accidental copy constructor std::negation<std::is_same<std::decay_t<T>, QStringView>> @@ -146,7 +142,7 @@ private: using if_compatible_pointer = typename std::enable_if<QtPrivate::IsCompatiblePointer<Pointer>::value, bool>::type; template <typename T> - using if_compatible_qstring_like = typename std::enable_if<std::is_same<T, QString>::value || std::is_same<T, QStringRef>::value, bool>::type; + using if_compatible_qstring_like = typename std::enable_if<std::is_same<T, QString>::value, bool>::type; template <typename T> using if_compatible_container = typename std::enable_if<QtPrivate::IsContainerCompatibleWithQStringView<T>::value, bool>::type; @@ -217,7 +213,6 @@ public: #ifdef Q_CLANG_QDOC QStringView(const QString &str) noexcept; - QStringView(const QStringRef &str) noexcept; #else template <typename String, if_compatible_qstring_like<String> = true> QStringView(const String &str) noexcept @@ -415,7 +410,7 @@ private: Q_DECLARE_TYPEINFO(QStringView, Q_PRIMITIVE_TYPE); template <typename QStringLike, typename std::enable_if< - std::is_same<QStringLike, QString>::value || std::is_same<QStringLike, QStringRef>::value, + std::is_same<QStringLike, QString>::value, bool>::type = true> inline QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept { return QStringView(s.data(), s.size()); } |