diff options
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index e63f1ce253..e6b4cc4b4f 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -4056,7 +4056,7 @@ int QString::count(const QRegExp& rx) const */ int QString::indexOf(const QRegularExpression& re, int from) const { - return indexOf(re, from, Q_NULLPTR); + return indexOf(re, from, nullptr); } /*! @@ -4107,7 +4107,7 @@ int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionM */ int QString::lastIndexOf(const QRegularExpression &re, int from) const { - return lastIndexOf(re, from, Q_NULLPTR); + return lastIndexOf(re, from, nullptr); } /*! @@ -4159,7 +4159,7 @@ int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpress */ bool QString::contains(const QRegularExpression &re) const { - return contains(re, Q_NULLPTR); + return contains(re, nullptr); } /*! @@ -8506,7 +8506,7 @@ bool QString::isSimpleText() const */ bool QString::isRightToLeft() const { - return QStringRef(this).isRightToLeft(); + return QtPrivate::isRightToLeft(QStringView(*this)); } /*! \fn QChar *QString::data() @@ -10778,8 +10778,23 @@ int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const */ bool QStringRef::isRightToLeft() const { - const ushort *p = reinterpret_cast<const ushort*>(unicode()); - const ushort * const end = p + size(); + return QtPrivate::isRightToLeft(QStringView(unicode(), size())); +} + +/*! + \since 5.11 + \internal + \relates QStringView + + Returns \c true if the string is read right to left. + + \sa QString::isRightToLeft() +*/ +bool QtPrivate::isRightToLeft(QStringView string) +{ + const ushort *p = reinterpret_cast<const ushort*>(string.data()); + const ushort * const end = p + string.size(); + int isolateLevel = 0; while (p < end) { uint ucs4 = *p; if (QChar::isHighSurrogate(ucs4) && p < end - 1) { @@ -10791,10 +10806,23 @@ bool QStringRef::isRightToLeft() const } switch (QChar::direction(ucs4)) { + case QChar::DirRLI: + case QChar::DirLRI: + case QChar::DirFSI: + ++isolateLevel; + break; + case QChar::DirPDI: + if (isolateLevel) + --isolateLevel; + break; case QChar::DirL: + if (isolateLevel) + break; return false; case QChar::DirR: case QChar::DirAL: + if (isolateLevel) + break; return true; default: break; |