diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index fd51ce321d..dd57af9f0f 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -7958,33 +7958,12 @@ bool QString::isSimpleText() const /*! \fn bool QString::isRightToLeft() const Returns \c true if the string is read right to left. + + \sa QStringRef::isRightToLeft() */ bool QString::isRightToLeft() const { - const ushort *p = d->data(); - const ushort * const end = p + d->size; - while (p < end) { - uint ucs4 = *p; - if (QChar::isHighSurrogate(ucs4) && p < end - 1) { - ushort low = p[1]; - if (QChar::isLowSurrogate(low)) { - ucs4 = QChar::surrogateToUcs4(ucs4, low); - ++p; - } - } - switch (QChar::direction(ucs4)) - { - case QChar::DirL: - return false; - case QChar::DirR: - case QChar::DirAL: - return true; - default: - break; - } - ++p; - } - return false; + return QStringRef(this).isRightToLeft(); } /*! \fn QChar *QString::data() @@ -9907,6 +9886,41 @@ int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const return qt_string_count(unicode(), size(), 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 +{ + const ushort *p = reinterpret_cast(unicode()); + const ushort * const end = p + size(); + while (p < end) { + uint ucs4 = *p; + if (QChar::isHighSurrogate(ucs4) && p < end - 1) { + ushort low = p[1]; + if (QChar::isLowSurrogate(low)) { + ucs4 = QChar::surrogateToUcs4(ucs4, low); + ++p; + } + } + switch (QChar::direction(ucs4)) + { + case QChar::DirL: + return false; + case QChar::DirR: + case QChar::DirAL: + return true; + default: + break; + } + ++p; + } + return false; +} + /*! \since 4.8 diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 8b7528577c..b370056d28 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -1450,6 +1450,8 @@ public: m_size -= n; } + bool isRightToLeft() const; + bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;