diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-06-16 10:23:19 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-06-16 22:46:16 +0200 |
commit | 1b10ce6a08edbc2ac7e8fd7e97e3fc691f2081df (patch) | |
tree | 34ab485d1dd9435369709b5e77c11af6dec78c22 /src/quick/util | |
parent | b65eee039092fa664e781cdd98a4bb5e66815218 (diff) |
Port QtDeclarative from QStringRef to QStringView
Task-number: QTBUG-84319
Change-Id: I2dcfb8a2db98282c7a1acdad1e6f4f949f26df15
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/quick/util')
-rw-r--r-- | src/quick/util/qquickanimation.cpp | 2 | ||||
-rw-r--r-- | src/quick/util/qquickglobal.cpp | 28 | ||||
-rw-r--r-- | src/quick/util/qquickstategroup.cpp | 12 | ||||
-rw-r--r-- | src/quick/util/qquickstyledtext.cpp | 44 |
4 files changed, 43 insertions, 43 deletions
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp index ded353a90a..82d6ca26be 100644 --- a/src/quick/util/qquickanimation.cpp +++ b/src/quick/util/qquickanimation.cpp @@ -1010,7 +1010,7 @@ void QQuickScriptActionPrivate::debugAction(QDebug d, int indentLevel) const QByteArray ind(indentLevel, u' '); QString exprStr = expr.expression(); int endOfFirstLine = exprStr.indexOf(u'\n'); - d << "\n" << ind.constData() << exprStr.leftRef(endOfFirstLine); + d << "\n" << ind.constData() << QStringView{exprStr}.left(endOfFirstLine); if (endOfFirstLine != -1 && endOfFirstLine < exprStr.length()) d << "..."; } diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index f5d4a54e74..2c20f1c76a 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -178,8 +178,8 @@ public: int index = s.indexOf(QLatin1Char(',')); bool xGood, yGood; - float xCoord = s.leftRef(index).toFloat(&xGood); - float yCoord = s.midRef(index + 1).toFloat(&yGood); + float xCoord = QStringView{s}.left(index).toFloat(&xGood); + float yCoord = QStringView{s}.mid(index + 1).toFloat(&yGood); if (xGood && yGood) { if (ok) *ok = true; @@ -198,9 +198,9 @@ public: int index2 = s.indexOf(QLatin1Char(','), index+1); bool xGood, yGood, zGood; - float xCoord = s.leftRef(index).toFloat(&xGood); - float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood); - float zCoord = s.midRef(index2 + 1).toFloat(&zGood); + float xCoord = QStringView{s}.left(index).toFloat(&xGood); + float yCoord = QStringView{s}.mid(index + 1, index2 - index - 1).toFloat(&yGood); + float zCoord = QStringView{s}.mid(index2 + 1).toFloat(&zGood); if (xGood && yGood && zGood) { if (ok) *ok = true; @@ -220,10 +220,10 @@ public: int index3 = s.indexOf(QLatin1Char(','), index2+1); bool xGood, yGood, zGood, wGood; - float xCoord = s.leftRef(index).toFloat(&xGood); - float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood); - float zCoord = s.midRef(index2 + 1, index3 - index2 - 1).toFloat(&zGood); - float wCoord = s.midRef(index3 + 1).toFloat(&wGood); + float xCoord = QStringView{s}.left(index).toFloat(&xGood); + float yCoord = QStringView{s}.mid(index + 1, index2 - index - 1).toFloat(&yGood); + float zCoord = QStringView{s}.mid(index2 + 1, index3 - index2 - 1).toFloat(&zGood); + float wCoord = QStringView{s}.mid(index3 + 1).toFloat(&wGood); if (xGood && yGood && zGood && wGood) { if (ok) *ok = true; @@ -243,10 +243,10 @@ public: int index3 = s.indexOf(QLatin1Char(','), index2+1); bool sGood, xGood, yGood, zGood; - qreal sCoord = s.leftRef(index).toDouble(&sGood); - qreal xCoord = s.midRef(index+1, index2-index-1).toDouble(&xGood); - qreal yCoord = s.midRef(index2+1, index3-index2-1).toDouble(&yGood); - qreal zCoord = s.midRef(index3+1).toDouble(&zGood); + qreal sCoord = QStringView{s}.left(index).toDouble(&sGood); + qreal xCoord = QStringView{s}.mid(index+1, index2-index-1).toDouble(&xGood); + qreal yCoord = QStringView{s}.mid(index2+1, index3-index2-1).toDouble(&yGood); + qreal zCoord = QStringView{s}.mid(index3+1).toDouble(&zGood); if (sGood && xGood && yGood && zGood) { if (ok) *ok = true; @@ -263,7 +263,7 @@ public: if (s.count(QLatin1Char(',')) == 15) { float matValues[16]; bool vOK = true; - QStringRef mutableStr(&s); + QStringView mutableStr(s); for (int i = 0; vOK && i < 16; ++i) { int cidx = mutableStr.indexOf(QLatin1Char(',')); matValues[i] = mutableStr.left(cidx).toDouble(&vOK); diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp index 2109aafc10..9cb3e26c04 100644 --- a/src/quick/util/qquickstategroup.cpp +++ b/src/quick/util/qquickstategroup.cpp @@ -420,26 +420,26 @@ QQuickTransition *QQuickStateGroupPrivate::findTransition(const QString &from, c const QString fromStateStr = t->fromState(); const QString toStateStr = t->toState(); - QVector<QStringRef> fromState = fromStateStr.splitRef(QLatin1Char(',')); + auto fromState = QStringView{fromStateStr}.split(QLatin1Char(',')); for (int jj = 0; jj < fromState.count(); ++jj) fromState[jj] = fromState.at(jj).trimmed(); - QVector<QStringRef> toState = toStateStr.splitRef(QLatin1Char(',')); + auto toState = QStringView{toStateStr}.split(QLatin1Char(',')); for (int jj = 0; jj < toState.count(); ++jj) toState[jj] = toState.at(jj).trimmed(); if (ii == 1) qSwap(fromState, toState); int tScore = 0; const QString asterisk = QStringLiteral("*"); - if (fromState.contains(QStringRef(&from))) + if (fromState.contains(QStringView(from))) tScore += 2; - else if (fromState.contains(QStringRef(&asterisk))) + else if (fromState.contains(QStringView(asterisk))) tScore += 1; else continue; - if (toState.contains(QStringRef(&to))) + if (toState.contains(QStringView(to))) tScore += 2; - else if (toState.contains(QStringRef(&asterisk))) + else if (toState.contains(QStringView(asterisk))) tScore += 1; else continue; diff --git a/src/quick/util/qquickstyledtext.cpp b/src/quick/util/qquickstyledtext.cpp index 660852ba83..053aa9823f 100644 --- a/src/quick/util/qquickstyledtext.cpp +++ b/src/quick/util/qquickstyledtext.cpp @@ -104,8 +104,8 @@ public: bool parseUnorderedListAttributes(const QChar *&ch, const QString &textIn); bool parseAnchorAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format); void parseImageAttributes(const QChar *&ch, const QString &textIn, QString &textOut); - QPair<QStringRef,QStringRef> parseAttribute(const QChar *&ch, const QString &textIn); - QStringRef parseValue(const QChar *&ch, const QString &textIn); + QPair<QStringView,QStringView> parseAttribute(const QChar *&ch, const QString &textIn); + QStringView parseValue(const QChar *&ch, const QString &textIn); void setFontSize(int size, QTextCharFormat &format); inline void skipSpace(const QChar *&ch) { @@ -298,7 +298,7 @@ void QQuickStyledTextPrivate::appendText(const QString &textIn, int start, int l { if (prependSpace) textOut.append(space); - textOut.append(QStringRef(&textIn, start, length)); + textOut.append(QStringView(textIn).mid(start, length)); prependSpace = false; hasSpace = false; hasNewLine = false; @@ -328,7 +328,7 @@ bool QQuickStyledTextPrivate::parseTag(const QChar *&ch, const QString &textIn, if (*ch == greaterThan) { if (tagLength == 0) return false; - QStringRef tag(&textIn, tagStart, tagLength); + auto tag = QStringView(textIn).mid(tagStart, tagLength); const QChar char0 = tag.at(0); if (char0 == QLatin1Char('b')) { if (tagLength == 1) { @@ -437,7 +437,7 @@ bool QQuickStyledTextPrivate::parseTag(const QChar *&ch, const QString &textIn, return false; } else if (ch->isSpace()) { // may have params. - QStringRef tag(&textIn, tagStart, tagLength); + auto tag = QStringView(textIn).mid(tagStart, tagLength); if (tag == QLatin1String("font")) return parseFontAttributes(ch, textIn, format); if (tag == QLatin1String("ol")) { @@ -475,7 +475,7 @@ bool QQuickStyledTextPrivate::parseCloseTag(const QChar *&ch, const QString &tex if (*ch == greaterThan) { if (tagLength == 0) return false; - QStringRef tag(&textIn, tagStart, tagLength); + auto tag = QStringView(textIn).mid(tagStart, tagLength); const QChar char0 = tag.at(0); hasNewLine = false; if (char0 == QLatin1Char('b')) { @@ -555,7 +555,7 @@ void QQuickStyledTextPrivate::parseEntity(const QChar *&ch, const QString &textI int entityLength = 0; while (!ch->isNull()) { if (*ch == QLatin1Char(';')) { - QStringRef entity(&textIn, entityStart, entityLength); + auto entity = QStringView(textIn).mid(entityStart, entityLength); if (entity == QLatin1String("gt")) textOut += QChar(62); else if (entity == QLatin1String("lt")) @@ -568,7 +568,7 @@ void QQuickStyledTextPrivate::parseEntity(const QChar *&ch, const QString &textI textOut += QChar(QChar::Nbsp); return; } else if (*ch == QLatin1Char(' ')) { - QStringRef entity(&textIn, entityStart - 1, entityLength + 1); + auto entity = QStringView(textIn).mid(entityStart - 1, entityLength + 1); textOut += entity + *ch; return; } @@ -580,7 +580,7 @@ void QQuickStyledTextPrivate::parseEntity(const QChar *&ch, const QString &textI bool QQuickStyledTextPrivate::parseFontAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format) { bool valid = false; - QPair<QStringRef,QStringRef> attr; + QPair<QStringView,QStringView> attr; do { attr = parseAttribute(ch, textIn); if (attr.first == QLatin1String("color")) { @@ -608,7 +608,7 @@ bool QQuickStyledTextPrivate::parseOrderedListAttributes(const QChar *&ch, const listItem.type = Ordered; listItem.format = Decimal; - QPair<QStringRef,QStringRef> attr; + QPair<QStringView,QStringView> attr; do { attr = parseAttribute(ch, textIn); if (attr.first == QLatin1String("type")) { @@ -637,7 +637,7 @@ bool QQuickStyledTextPrivate::parseUnorderedListAttributes(const QChar *&ch, con listItem.type = Unordered; listItem.format = Bullet; - QPair<QStringRef,QStringRef> attr; + QPair<QStringView,QStringView> attr; do { attr = parseAttribute(ch, textIn); if (attr.first == QLatin1String("type")) { @@ -657,7 +657,7 @@ bool QQuickStyledTextPrivate::parseAnchorAttributes(const QChar *&ch, const QStr { bool valid = false; - QPair<QStringRef,QStringRef> attr; + QPair<QStringView,QStringView> attr; do { attr = parseAttribute(ch, textIn); if (attr.first == QLatin1String("href")) { @@ -682,7 +682,7 @@ void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QStri QQuickStyledTextImgTag *image = new QQuickStyledTextImgTag; image->position = textOut.length() + (trailingSpace ? 0 : 1); - QPair<QStringRef,QStringRef> attr; + QPair<QStringView,QStringView> attr; do { attr = parseAttribute(ch, textIn); if (attr.first == QLatin1String("src")) { @@ -727,7 +727,7 @@ void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QStri image->position = textOut.length() + (trailingSpace ? 0 : 1); imgWidth = image->size.width(); image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0; - QPair<QStringRef,QStringRef> attr; + QPair<QStringView,QStringView> attr; do { attr = parseAttribute(ch, textIn); } while (!ch->isNull() && !attr.first.isEmpty()); @@ -740,7 +740,7 @@ void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QStri textOut += padding + QLatin1Char(' '); } -QPair<QStringRef,QStringRef> QQuickStyledTextPrivate::parseAttribute(const QChar *&ch, const QString &textIn) +QPair<QStringView,QStringView> QQuickStyledTextPrivate::parseAttribute(const QChar *&ch, const QString &textIn) { skipSpace(ch); @@ -759,10 +759,10 @@ QPair<QStringRef,QStringRef> QQuickStyledTextPrivate::parseAttribute(const QChar ++ch; if (!attrLength) break; - QStringRef attr(&textIn, attrStart, attrLength); - QStringRef val = parseValue(ch, textIn); + auto attr = QStringView(textIn).mid(attrStart, attrLength); + QStringView val = parseValue(ch, textIn); if (!val.isEmpty()) - return QPair<QStringRef,QStringRef>(attr,val); + return QPair<QStringView,QStringView>(attr,val); break; } else { ++attrLength; @@ -770,10 +770,10 @@ QPair<QStringRef,QStringRef> QQuickStyledTextPrivate::parseAttribute(const QChar ++ch; } - return QPair<QStringRef,QStringRef>(); + return QPair<QStringView,QStringView>(); } -QStringRef QQuickStyledTextPrivate::parseValue(const QChar *&ch, const QString &textIn) +QStringView QQuickStyledTextPrivate::parseValue(const QChar *&ch, const QString &textIn) { int valStart = ch - textIn.constData(); int valLength = 0; @@ -782,10 +782,10 @@ QStringRef QQuickStyledTextPrivate::parseValue(const QChar *&ch, const QString & ++ch; } if (ch->isNull()) - return QStringRef(); + return QStringView(); ++ch; // skip quote - return QStringRef(&textIn, valStart, valLength); + return QStringView(textIn).mid(valStart, valLength); } QString QQuickStyledTextPrivate::toAlpha(int value, bool upper) |