Port QtWidgets from QStringRef to QStringView
Change-Id: Ibe348e7aea838ab8c2d628bb43709c867a506637 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
be61790a9e
commit
6c108ee0c4
@ -1151,12 +1151,12 @@ Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path)
|
|||||||
if (separatorPosition < 0)
|
if (separatorPosition < 0)
|
||||||
separatorPosition = path.size();
|
separatorPosition = path.size();
|
||||||
if (separatorPosition == 1) {
|
if (separatorPosition == 1) {
|
||||||
return QDir::homePath() + path.midRef(1);
|
return QDir::homePath() + QStringView{path}.mid(1);
|
||||||
} else {
|
} else {
|
||||||
#if defined(Q_OS_VXWORKS) || defined(Q_OS_INTEGRITY)
|
#if defined(Q_OS_VXWORKS) || defined(Q_OS_INTEGRITY)
|
||||||
const QString homePath = QDir::homePath();
|
const QString homePath = QDir::homePath();
|
||||||
#else
|
#else
|
||||||
const QByteArray userName = path.midRef(1, separatorPosition - 1).toLocal8Bit();
|
const QByteArray userName = QStringView{path}.mid(1, separatorPosition - 1).toLocal8Bit();
|
||||||
# if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_WASM)
|
# if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_WASM)
|
||||||
passwd pw;
|
passwd pw;
|
||||||
passwd *tmpPw;
|
passwd *tmpPw;
|
||||||
@ -1178,7 +1178,7 @@ Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path)
|
|||||||
const QString homePath = QString::fromLocal8Bit(pw->pw_dir);
|
const QString homePath = QString::fromLocal8Bit(pw->pw_dir);
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
return homePath + path.midRef(separatorPosition);
|
return homePath + QStringView{path}.mid(separatorPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -4051,11 +4051,11 @@ QString QFileDialogPrivate::getEnvironmentVariable(const QString &string)
|
|||||||
{
|
{
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
if (string.size() > 1 && string.startsWith(QLatin1Char('$'))) {
|
if (string.size() > 1 && string.startsWith(QLatin1Char('$'))) {
|
||||||
return QString::fromLocal8Bit(qgetenv(string.midRef(1).toLatin1().constData()));
|
return QString::fromLocal8Bit(qgetenv(QStringView{string}.mid(1).toLatin1().constData()));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (string.size() > 2 && string.startsWith(QLatin1Char('%')) && string.endsWith(QLatin1Char('%'))) {
|
if (string.size() > 2 && string.startsWith(QLatin1Char('%')) && string.endsWith(QLatin1Char('%'))) {
|
||||||
return QString::fromLocal8Bit(qgetenv(string.midRef(1, string.size() - 2).toLatin1().constData()));
|
return QString::fromLocal8Bit(qgetenv(QStringView{string}.mid(1, string.size() - 2).toLatin1().constData()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return string;
|
return string;
|
||||||
|
@ -1697,7 +1697,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
|
|||||||
|
|
||||||
QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
|
QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
|
||||||
QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
|
QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
|
||||||
QStringRef s(&menuitem->text);
|
QStringView s(menuitem->text);
|
||||||
if (!s.isEmpty()) { // draw text
|
if (!s.isEmpty()) { // draw text
|
||||||
p->save();
|
p->save();
|
||||||
int t = s.indexOf(QLatin1Char('\t'));
|
int t = s.indexOf(QLatin1Char('\t'));
|
||||||
|
@ -3781,7 +3781,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
|
|||||||
textRect.setWidth(textRect.width() - mi.tabWidth);
|
textRect.setWidth(textRect.width() - mi.tabWidth);
|
||||||
const QRect vTextRect = visualRect(opt->direction, m->rect, textRect);
|
const QRect vTextRect = visualRect(opt->direction, m->rect, textRect);
|
||||||
|
|
||||||
QStringRef s(&mi.text);
|
QStringView s(mi.text);
|
||||||
p->setPen(mi.palette.buttonText().color());
|
p->setPen(mi.palette.buttonText().color());
|
||||||
if (!s.isEmpty()) {
|
if (!s.isEmpty()) {
|
||||||
int text_flags = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
|
int text_flags = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
|
||||||
|
@ -1190,7 +1190,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
|
|||||||
QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
|
QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
|
||||||
w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
|
w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
|
||||||
QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
|
QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
|
||||||
QStringRef s(&menuitem->text);
|
QStringView s(menuitem->text);
|
||||||
if (!s.isEmpty()) { // draw text
|
if (!s.isEmpty()) { // draw text
|
||||||
p->save();
|
p->save();
|
||||||
int t = s.indexOf(QLatin1Char('\t'));
|
int t = s.indexOf(QLatin1Char('\t'));
|
||||||
|
@ -984,7 +984,7 @@ static bool completeOnLoaded(const QFileSystemModel *model,
|
|||||||
// The user is typing something within that directory and is not in a subdirectory yet.
|
// The user is typing something within that directory and is not in a subdirectory yet.
|
||||||
const auto separator = QLatin1Char('/');
|
const auto separator = QLatin1Char('/');
|
||||||
return prefix.startsWith(path, caseSensitivity) && prefix.at(pathSize) == separator
|
return prefix.startsWith(path, caseSensitivity) && prefix.at(pathSize) == separator
|
||||||
&& !prefix.rightRef(prefixSize - pathSize - 1).contains(separator);
|
&& !QStringView{prefix}.right(prefixSize - pathSize - 1).contains(separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &path)
|
void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &path)
|
||||||
|
@ -1482,7 +1482,7 @@ QStyle::SubControl QAbstractSpinBoxPrivate::newHoverControl(const QPoint &pos)
|
|||||||
|
|
||||||
QString QAbstractSpinBoxPrivate::stripped(const QString &t, int *pos) const
|
QString QAbstractSpinBoxPrivate::stripped(const QString &t, int *pos) const
|
||||||
{
|
{
|
||||||
QStringRef text(&t);
|
QStringView text(t);
|
||||||
if (specialValueText.size() == 0 || text != specialValueText) {
|
if (specialValueText.size() == 0 || text != specialValueText) {
|
||||||
int from = 0;
|
int from = 0;
|
||||||
int size = text.size();
|
int size = text.size();
|
||||||
|
@ -107,7 +107,7 @@ QString QCalendarDateSectionValidator::highlightString(const QString &str, int p
|
|||||||
if (pos == 0)
|
if (pos == 0)
|
||||||
return QLatin1String("<b>") + str + QLatin1String("</b>");
|
return QLatin1String("<b>") + str + QLatin1String("</b>");
|
||||||
int startPos = str.length() - pos;
|
int startPos = str.length() - pos;
|
||||||
return str.midRef(0, startPos) + QLatin1String("<b>") + str.midRef(startPos, pos) + QLatin1String("</b>");
|
return QStringView{str}.mid(0, startPos) + QLatin1String("<b>") + QStringView{str}.mid(startPos, pos) + QLatin1String("</b>");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +548,7 @@ void QCalendarDateValidator::setFormat(const QString &format)
|
|||||||
bool quoting = false;
|
bool quoting = false;
|
||||||
QString separator;
|
QString separator;
|
||||||
while (pos < format.size()) {
|
while (pos < format.size()) {
|
||||||
const QStringRef mid = format.midRef(pos);
|
const QStringView mid = QStringView{format}.mid(pos);
|
||||||
int offset = 1;
|
int offset = 1;
|
||||||
|
|
||||||
if (mid.startsWith(quote)) {
|
if (mid.startsWith(quote)) {
|
||||||
|
@ -106,7 +106,7 @@ void QLineEditPrivate::_q_completionHighlighted(const QString &newText)
|
|||||||
} else {
|
} else {
|
||||||
int c = control->cursor();
|
int c = control->cursor();
|
||||||
QString text = control->text();
|
QString text = control->text();
|
||||||
q->setText(text.leftRef(c) + newText.midRef(c));
|
q->setText(QStringView{text}.left(c) + QStringView{newText}.mid(c));
|
||||||
control->moveCursor(control->end(), false);
|
control->moveCursor(control->end(), false);
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
const bool mark = true;
|
const bool mark = true;
|
||||||
|
@ -1539,13 +1539,13 @@ static QString computeElidedText(Qt::TextElideMode mode, const QString &text)
|
|||||||
QString ret;
|
QString ret;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case Qt::ElideRight:
|
case Qt::ElideRight:
|
||||||
ret = text.leftRef(2) + Ellipses;
|
ret = QStringView{text}.left(2) + Ellipses;
|
||||||
break;
|
break;
|
||||||
case Qt::ElideMiddle:
|
case Qt::ElideMiddle:
|
||||||
ret = text.leftRef(1) + Ellipses + text.rightRef(1);
|
ret = QStringView{text}.left(1) + Ellipses + QStringView{text}.right(1);
|
||||||
break;
|
break;
|
||||||
case Qt::ElideLeft:
|
case Qt::ElideLeft:
|
||||||
ret = Ellipses + text.rightRef(2);
|
ret = Ellipses + QStringView{text}.right(2);
|
||||||
break;
|
break;
|
||||||
case Qt::ElideNone:
|
case Qt::ElideNone:
|
||||||
ret = text;
|
ret = text;
|
||||||
|
@ -326,7 +326,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType
|
|||||||
qWarning("QTextBrowser: No document for %s", url.toString().toLatin1().constData());
|
qWarning("QTextBrowser: No document for %s", url.toString().toLatin1().constData());
|
||||||
|
|
||||||
if (q->isVisible()) {
|
if (q->isVisible()) {
|
||||||
const QStringRef firstTag = txt.leftRef(txt.indexOf(QLatin1Char('>')) + 1);
|
const QStringView firstTag = QStringView{txt}.left(txt.indexOf(QLatin1Char('>')) + 1);
|
||||||
if (firstTag.startsWith(QLatin1String("<qt")) && firstTag.contains(QLatin1String("type")) && firstTag.contains(QLatin1String("detail"))) {
|
if (firstTag.startsWith(QLatin1String("<qt")) && firstTag.contains(QLatin1String("type")) && firstTag.contains(QLatin1String("detail"))) {
|
||||||
#ifndef QT_NO_CURSOR
|
#ifndef QT_NO_CURSOR
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
|
@ -1215,14 +1215,14 @@ QString QWidgetLineControl::maskString(int pos, const QString &str, bool clear)
|
|||||||
int n = findInMask(i, true, true, str[(int)strIndex]);
|
int n = findInMask(i, true, true, str[(int)strIndex]);
|
||||||
if (n != -1) {
|
if (n != -1) {
|
||||||
if (str.length() != 1 || i == 0 || (i > 0 && (!m_maskData[i-1].separator || m_maskData[i-1].maskChar != str[(int)strIndex]))) {
|
if (str.length() != 1 || i == 0 || (i > 0 && (!m_maskData[i-1].separator || m_maskData[i-1].maskChar != str[(int)strIndex]))) {
|
||||||
s += fill.midRef(i, n - i + 1);
|
s += QStringView{fill}.mid(i, n - i + 1);
|
||||||
i = n + 1; // update i to find + 1
|
i = n + 1; // update i to find + 1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// search for valid m_blank if not
|
// search for valid m_blank if not
|
||||||
n = findInMask(i, true, false, str[(int)strIndex]);
|
n = findInMask(i, true, false, str[(int)strIndex]);
|
||||||
if (n != -1) {
|
if (n != -1) {
|
||||||
s += fill.midRef(i, n - i);
|
s += QStringView{fill}.mid(i, n - i);
|
||||||
switch (m_maskData[n].caseMode) {
|
switch (m_maskData[n].caseMode) {
|
||||||
case MaskInputData::Upper:
|
case MaskInputData::Upper:
|
||||||
s += str[(int)strIndex].toUpper();
|
s += str[(int)strIndex].toUpper();
|
||||||
|
@ -2208,7 +2208,7 @@ QVariant QWidgetTextControl::inputMethodQuery(Qt::InputMethodQuery property, QVa
|
|||||||
tmpCursor.movePosition(QTextCursor::NextBlock);
|
tmpCursor.movePosition(QTextCursor::NextBlock);
|
||||||
--numBlocks;
|
--numBlocks;
|
||||||
}
|
}
|
||||||
result += block.text().midRef(0, localPos);
|
result += QStringView{block.text()}.mid(0, localPos);
|
||||||
return QVariant(result);
|
return QVariant(result);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user