Port QtGui from QStringRef to QStringView

Task-number: QTBUG-84319
Change-Id: I1761096fbcc9421a013cf73f831a2a2ba0c18006
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
Lars Knoll 2020-05-25 14:25:06 +02:00
parent 82a0f4a193
commit d984adac68
15 changed files with 45 additions and 45 deletions

View File

@ -217,7 +217,7 @@ class QIconCacheGtkReader
{ {
public: public:
explicit QIconCacheGtkReader(const QString &themeDir); explicit QIconCacheGtkReader(const QString &themeDir);
QVector<const char *> lookup(const QStringRef &); QVector<const char *> lookup(QStringView);
bool isValid() const { return m_isValid; } bool isValid() const { return m_isValid; }
private: private:
QFile m_file; QFile m_file;
@ -290,7 +290,7 @@ static quint32 icon_name_hash(const char *p)
with this name is present. The char* are pointers to the mapped data. with this name is present. The char* are pointers to the mapped data.
For example, this would return { "32x32/apps", "24x24/apps" , ... } For example, this would return { "32x32/apps", "24x24/apps" , ... }
*/ */
QVector<const char *> QIconCacheGtkReader::lookup(const QStringRef &name) QVector<const char *> QIconCacheGtkReader::lookup(QStringView name)
{ {
QVector<const char *> ret; QVector<const char *> ret;
if (!isValid() || name.isEmpty()) if (!isValid() || name.isEmpty())
@ -443,7 +443,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
const QStringList contentDirs = theme.contentDirs(); const QStringList contentDirs = theme.contentDirs();
QStringRef iconNameFallback(&iconName); QStringView iconNameFallback(iconName);
// Iterate through all icon's fallbacks in current theme // Iterate through all icon's fallbacks in current theme
while (info.entries.isEmpty()) { while (info.entries.isEmpty()) {

View File

@ -5309,14 +5309,14 @@ QMap<QString, QString> qt_getImageText(const QImage &image, const QString &descr
QMap<QString, QString> qt_getImageTextFromDescription(const QString &description) QMap<QString, QString> qt_getImageTextFromDescription(const QString &description)
{ {
QMap<QString, QString> text; QMap<QString, QString> text;
const auto pairs = description.splitRef(QLatin1String("\n\n")); const auto pairs = QStringView{description}.split(u"\n\n");
for (const QStringRef &pair : pairs) { for (const auto &pair : pairs) {
int index = pair.indexOf(QLatin1Char(':')); int index = pair.indexOf(QLatin1Char(':'));
if (index >= 0 && pair.indexOf(QLatin1Char(' ')) < index) { if (index >= 0 && pair.indexOf(QLatin1Char(' ')) < index) {
if (!pair.trimmed().isEmpty()) if (!pair.trimmed().isEmpty())
text.insert(QLatin1String("Description"), pair.toString().simplified()); text.insert(QLatin1String("Description"), pair.toString().simplified());
} else { } else {
const QStringRef key = pair.left(index); const auto key = pair.left(index);
if (!key.trimmed().isEmpty()) if (!key.trimmed().isEmpty())
text.insert(key.toString(), pair.mid(index + 2).toString().simplified()); text.insert(key.toString(), pair.mid(index + 2).toString().simplified());
} }

View File

@ -851,7 +851,7 @@ static void set_text(const QImage &image, png_structp png_ptr, png_infop info_pt
QMap<QString, QString>::ConstIterator it = text.constBegin(); QMap<QString, QString>::ConstIterator it = text.constBegin();
int i = 0; int i = 0;
while (it != text.constEnd()) { while (it != text.constEnd()) {
text_ptr[i].key = qstrdup(it.key().leftRef(79).toLatin1().constData()); text_ptr[i].key = qstrdup(QStringView{it.key()}.left(79).toLatin1().constData());
bool noCompress = (it.value().length() < 40); bool noCompress = (it.value().length() < 40);
#ifdef PNG_iTXt_SUPPORTED #ifdef PNG_iTXt_SUPPORTED

View File

@ -505,8 +505,8 @@ void QHighDpiScaling::updateHighDpiScaling()
if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) { if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) {
int i = 0; int i = 0;
const QString spec = qEnvironmentVariable(screenFactorsEnvVar); const QString spec = qEnvironmentVariable(screenFactorsEnvVar);
const auto specs = spec.splitRef(QLatin1Char(';')); const auto specs = QStringView{spec}.split(u';');
for (const QStringRef &spec : specs) { for (const auto &spec : specs) {
int equalsPos = spec.lastIndexOf(QLatin1Char('=')); int equalsPos = spec.lastIndexOf(QLatin1Char('='));
qreal factor = 0; qreal factor = 0;
if (equalsPos > 0) { if (equalsPos > 0) {

View File

@ -1131,7 +1131,7 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
int i = 0; int i = 0;
int lastI = 0; int lastI = 0;
while ((i = sl.indexOf(QLatin1Char('+'), i + 1)) != -1) { while ((i = sl.indexOf(QLatin1Char('+'), i + 1)) != -1) {
const QStringRef sub = sl.midRef(lastI, i - lastI + 1); const QStringView sub = QStringView{sl}.mid(lastI, i - lastI + 1);
// If we get here the shortcuts contains at least one '+'. We break up // If we get here the shortcuts contains at least one '+'. We break up
// along the following strategy: // along the following strategy:
// Meta+Ctrl++ ( "Meta+", "Ctrl+", "+" ) // Meta+Ctrl++ ( "Meta+", "Ctrl+", "+" )
@ -1164,7 +1164,7 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
} }
int p = accel.lastIndexOf(QLatin1Char('+'), accel.length() - 2); // -2 so that Ctrl++ works int p = accel.lastIndexOf(QLatin1Char('+'), accel.length() - 2); // -2 so that Ctrl++ works
QStringRef accelRef(&accel); QStringView accelRef(accel);
if(p > 0) if(p > 0)
accelRef = accelRef.mid(p + 1); accelRef = accelRef.mid(p + 1);

View File

@ -867,10 +867,10 @@ QString QColor::name(NameFormat format) const
{ {
switch (format) { switch (format) {
case HexRgb: case HexRgb:
return QLatin1Char('#') + QString::number(rgba() | 0x1000000, 16).rightRef(6); return QLatin1Char('#') + QStringView{QString::number(rgba() | 0x1000000, 16)}.right(6);
case HexArgb: case HexArgb:
// it's called rgba() but it does return AARRGGBB // it's called rgba() but it does return AARRGGBB
return QLatin1Char('#') + QString::number(rgba() | Q_INT64_C(0x100000000), 16).rightRef(8); return QLatin1Char('#') + QStringView{QString::number(rgba() | Q_INT64_C(0x100000000), 16)}.right(8);
} }
return QString(); return QString();
} }

View File

@ -398,7 +398,7 @@ static QPageSize::PageSizeId qt_idForPpdKey(const QString &ppdKey, QSize *match
{ {
if (ppdKey.isEmpty()) if (ppdKey.isEmpty())
return QPageSize::Custom; return QPageSize::Custom;
QStringRef key(&ppdKey); QStringView key(ppdKey);
// Remove any Rotated or Tranverse modifiers // Remove any Rotated or Tranverse modifiers
if (key.endsWith(QLatin1String("Rotated"))) if (key.endsWith(QLatin1String("Rotated")))
key.chop(7); key.chop(7);

View File

@ -403,14 +403,14 @@ ValueExtractor::ValueExtractor(const QVector<Declaration> &decls, const QPalette
LengthData ValueExtractor::lengthValue(const Value& v) LengthData ValueExtractor::lengthValue(const Value& v)
{ {
const QString str = v.variant.toString(); const QString str = v.variant.toString();
QStringRef s(&str); QStringView s(str);
LengthData data; LengthData data;
data.unit = LengthData::None; data.unit = LengthData::None;
if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) if (s.endsWith(u"px", Qt::CaseInsensitive))
data.unit = LengthData::Px; data.unit = LengthData::Px;
else if (s.endsWith(QLatin1String("ex"), Qt::CaseInsensitive)) else if (s.endsWith(u"ex", Qt::CaseInsensitive))
data.unit = LengthData::Ex; data.unit = LengthData::Ex;
else if (s.endsWith(QLatin1String("em"), Qt::CaseInsensitive)) else if (s.endsWith(u"em", Qt::CaseInsensitive))
data.unit = LengthData::Em; data.unit = LengthData::Em;
if (data.unit != LengthData::None) if (data.unit != LengthData::None)
@ -1513,7 +1513,7 @@ bool Declaration::realValue(qreal *real, const char *unit) const
if (unit && v.type != Value::Length) if (unit && v.type != Value::Length)
return false; return false;
const QString str = v.variant.toString(); const QString str = v.variant.toString();
QStringRef s(&str); QStringView s(str);
if (unit) { if (unit) {
const QLatin1String unitStr(unit); const QLatin1String unitStr(unit);
if (!s.endsWith(unitStr, Qt::CaseInsensitive)) if (!s.endsWith(unitStr, Qt::CaseInsensitive))
@ -1532,7 +1532,7 @@ static bool intValueHelper(const QCss::Value &v, int *i, const char *unit)
if (unit && v.type != Value::Length) if (unit && v.type != Value::Length)
return false; return false;
const QString str = v.variant.toString(); const QString str = v.variant.toString();
QStringRef s(&str); QStringView s(str);
if (unit) { if (unit) {
const QLatin1String unitStr(unit); const QLatin1String unitStr(unit);
if (!s.endsWith(unitStr, Qt::CaseInsensitive)) if (!s.endsWith(unitStr, Qt::CaseInsensitive))
@ -1584,7 +1584,7 @@ QRect Declaration::rectValue() const
const QStringList func = v.variant.toStringList(); const QStringList func = v.variant.toStringList();
if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0) if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0)
return QRect(); return QRect();
const auto args = func[1].splitRef(QLatin1Char(' '), Qt::SkipEmptyParts); const auto args = QStringView{func[1]}.split(QLatin1Char(' '), Qt::SkipEmptyParts);
if (args.count() != 4) if (args.count() != 4)
return QRect(); return QRect();
QRect rect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt()); QRect rect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt());
@ -2009,8 +2009,8 @@ bool StyleSelector::basicSelectorMatches(const BasicSelector &sel, NodePtr node)
return false; return false;
break; break;
case QCss::AttributeSelector::MatchIncludes: { case QCss::AttributeSelector::MatchIncludes: {
const auto lst = attrValue.splitRef(QLatin1Char(' ')); const auto lst = QStringView{attrValue}.split(u' ');
if (!lst.contains(QStringRef(&a.value))) if (!lst.contains(QStringView(a.value)))
return false; return false;
break; break;
} }
@ -2189,7 +2189,7 @@ QString Scanner::preprocess(const QString &input, bool *hasEscapeSequences)
hexCount = qMin(hexCount, 6); hexCount = qMin(hexCount, 6);
bool ok = false; bool ok = false;
const char16_t code = output.midRef(hexStart, hexCount).toUShort(&ok, 16); const char16_t code = QStringView{output}.mid(hexStart, hexCount).toUShort(&ok, 16);
if (ok) { if (ok) {
output.replace(hexStart - 1, hexCount + 1, code); output.replace(hexStart - 1, hexCount + 1, code);
i = hexStart; i = hexStart;

View File

@ -2019,7 +2019,7 @@ size_t qHash(const QFont &font, size_t seed) noexcept
*/ */
bool QFont::fromString(const QString &descrip) bool QFont::fromString(const QString &descrip)
{ {
const QStringRef sr = QStringRef(&descrip).trimmed(); const auto sr = QStringView(descrip).trimmed();
const auto l = sr.split(QLatin1Char(',')); const auto l = sr.split(QLatin1Char(','));
const int count = l.count(); const int count = l.count();
if (!count || (count > 2 && count < 9) || count > 11 || if (!count || (count > 2 && count < 9) || count > 11 ||

View File

@ -105,7 +105,7 @@ static int getFontWeight(const QString &weightString)
return QFont::Light; return QFont::Light;
if (s == QLatin1String("thin")) if (s == QLatin1String("thin"))
return QFont::Thin; return QFont::Thin;
const QStringRef s2 = s.midRef(2); const QStringView s2 = QStringView{s}.mid(2);
if (s.startsWith(QLatin1String("ex")) || s.startsWith(QLatin1String("ul"))) { if (s.startsWith(QLatin1String("ex")) || s.startsWith(QLatin1String("ul"))) {
if (s2 == QLatin1String("tralight") || s == QLatin1String("tra light")) if (s2 == QLatin1String("tralight") || s == QLatin1String("tra light"))
return QFont::ExtraLight; return QFont::ExtraLight;
@ -511,11 +511,11 @@ static QStringList familyList(const QFontDef &req)
family_list << req.families; family_list << req.families;
if (!req.family.isEmpty()) { if (!req.family.isEmpty()) {
const auto list = req.family.splitRef(QLatin1Char(',')); const auto list = QStringView{req.family}.split(QLatin1Char(','));
const int numFamilies = list.size(); const int numFamilies = list.size();
family_list.reserve(numFamilies); family_list.reserve(numFamilies);
for (int i = 0; i < numFamilies; ++i) { for (int i = 0; i < numFamilies; ++i) {
QStringRef str = list.at(i).trimmed(); auto str = list.at(i).trimmed();
if ((str.startsWith(QLatin1Char('"')) && str.endsWith(QLatin1Char('"'))) if ((str.startsWith(QLatin1Char('"')) && str.endsWith(QLatin1Char('"')))
|| (str.startsWith(QLatin1Char('\'')) && str.endsWith(QLatin1Char('\'')))) || (str.startsWith(QLatin1Char('\'')) && str.endsWith(QLatin1Char('\''))))
str = str.mid(1, str.length() - 2); str = str.mid(1, str.length() - 2);

View File

@ -102,7 +102,7 @@ bool Qt::mightBeRichText(const QString& text)
++start; ++start;
// skip a leading <?xml ... ?> as for example with xhtml // skip a leading <?xml ... ?> as for example with xhtml
if (text.midRef(start, 5).compare(QLatin1String("<?xml")) == 0) { if (QStringView{text}.mid(start, 5).compare(QLatin1String("<?xml")) == 0) {
while (start < text.length()) { while (start < text.length()) {
if (text.at(start) == QLatin1Char('?') if (text.at(start) == QLatin1Char('?')
&& start + 2 < text.length() && start + 2 < text.length()
@ -117,12 +117,12 @@ bool Qt::mightBeRichText(const QString& text)
++start; ++start;
} }
if (text.midRef(start, 5).compare(QLatin1String("<!doc"), Qt::CaseInsensitive) == 0) if (QStringView{text}.mid(start, 5).compare(QLatin1String("<!doc"), Qt::CaseInsensitive) == 0)
return true; return true;
int open = start; int open = start;
while (open < text.length() && text.at(open) != QLatin1Char('<') while (open < text.length() && text.at(open) != QLatin1Char('<')
&& text.at(open) != QLatin1Char('\n')) { && text.at(open) != QLatin1Char('\n')) {
if (text.at(open) == QLatin1Char('&') && text.midRef(open + 1, 3) == QLatin1String("lt;")) if (text.at(open) == QLatin1Char('&') && QStringView{text}.mid(open + 1, 3) == QLatin1String("lt;"))
return true; // support desperate attempt of user to see <...> return true; // support desperate attempt of user to see <...>
++open; ++open;
} }

View File

@ -132,7 +132,7 @@ static bool isValidBlockSeparator(QChar ch)
|| ch == QTextEndOfFrame; || ch == QTextEndOfFrame;
} }
static bool noBlockInString(const QStringRef &str) static bool noBlockInString(QStringView str)
{ {
return !str.contains(QChar::ParagraphSeparator) return !str.contains(QChar::ParagraphSeparator)
&& !str.contains(QTextBeginningOfFrame) && !str.contains(QTextBeginningOfFrame)
@ -323,7 +323,7 @@ void QTextDocumentPrivate::setLayout(QAbstractTextDocumentLayout *layout)
void QTextDocumentPrivate::insert_string(int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op) void QTextDocumentPrivate::insert_string(int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op)
{ {
// ##### optimize when only appending to the fragment! // ##### optimize when only appending to the fragment!
Q_ASSERT(noBlockInString(text.midRef(strPos, length))); Q_ASSERT(noBlockInString(QStringView{text}.mid(strPos, length)));
split(pos); split(pos);
uint x = fragments.insert_single(pos, length); uint x = fragments.insert_single(pos, length);
@ -479,7 +479,7 @@ void QTextDocumentPrivate::insert(int pos, const QString &str, int format)
if (str.size() == 0) if (str.size() == 0)
return; return;
Q_ASSERT(noBlockInString(QStringRef(&str))); Q_ASSERT(noBlockInString(str));
int strPos = text.length(); int strPos = text.length();
text.append(str); text.append(str);
@ -497,7 +497,7 @@ int QTextDocumentPrivate::remove_string(int pos, uint length, QTextUndoCommand::
Q_ASSERT(blocks.size(b) > length); Q_ASSERT(blocks.size(b) > length);
Q_ASSERT(x && fragments.position(x) == (uint)pos && fragments.size(x) == length); Q_ASSERT(x && fragments.position(x) == (uint)pos && fragments.size(x) == length);
Q_ASSERT(noBlockInString(text.midRef(fragments.fragment(x)->stringPosition, length))); Q_ASSERT(noBlockInString(QStringView{text}.mid(fragments.fragment(x)->stringPosition, length)));
blocks.setSize(b, blocks.size(b)-length); blocks.setSize(b, blocks.size(b)-length);
@ -632,7 +632,7 @@ void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::O
if (key+1 != blocks.position(b)) { if (key+1 != blocks.position(b)) {
// qDebug("remove_string from %d length %d", key, X->size_array[0]); // qDebug("remove_string from %d length %d", key, X->size_array[0]);
Q_ASSERT(noBlockInString(text.midRef(X->stringPosition, X->size_array[0]))); Q_ASSERT(noBlockInString(QStringView{text}.mid(X->stringPosition, X->size_array[0])));
w = remove_string(key, X->size_array[0], op); w = remove_string(key, X->size_array[0], op);
if (needsInsert) { if (needsInsert) {

View File

@ -2979,7 +2979,7 @@ static QString stringMidRetainingBidiCC(const QString &string,
suffix += c; suffix += c;
} }
return prefix + ellidePrefix + string.midRef(midStart, midLength) + ellideSuffix + suffix; return prefix + ellidePrefix + QStringView{string}.mid(midStart, midLength) + ellideSuffix + suffix;
} }
QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int flags, int from, int count) const QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int flags, int from, int count) const
@ -3154,7 +3154,7 @@ QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int
if (prevCharJoins(layoutData->string, rightPos)) if (prevCharJoins(layoutData->string, rightPos))
ellipsisText.append(ZWJ); ellipsisText.append(ZWJ);
return layoutData->string.midRef(from, leftPos - from) + ellipsisText + layoutData->string.midRef(rightPos, to - rightPos); return QStringView{layoutData->string}.mid(from, leftPos - from) + ellipsisText + QStringView{layoutData->string}.mid(rightPos, to - rightPos);
} }
return layoutData->string.mid(from, to - from); return layoutData->string.mid(from, to - from);

View File

@ -328,17 +328,17 @@ bool operator<(const QTextHtmlEntity &entity1, const QTextHtmlEntity &entity2)
} }
#endif #endif
static bool operator<(const QStringRef &entityStr, const QTextHtmlEntity &entity) static bool operator<(QStringView entityStr, const QTextHtmlEntity &entity)
{ {
return entityStr < QLatin1String(entity.name); return entityStr < QLatin1String(entity.name);
} }
static bool operator<(const QTextHtmlEntity &entity, const QStringRef &entityStr) static bool operator<(const QTextHtmlEntity &entity, QStringView entityStr)
{ {
return QLatin1String(entity.name) < entityStr; return QLatin1String(entity.name) < entityStr;
} }
static QChar resolveEntity(const QStringRef &entity) static QChar resolveEntity(QStringView entity)
{ {
const QTextHtmlEntity *start = &entities[0]; const QTextHtmlEntity *start = &entities[0];
const QTextHtmlEntity *end = &entities[MAX_ENTITY]; const QTextHtmlEntity *end = &entities[MAX_ENTITY];
@ -804,7 +804,7 @@ QString QTextHtmlParser::parseEntity()
{ {
const int recover = pos; const int recover = pos;
int entityLen = 0; int entityLen = 0;
QStringRef entity; QStringView entity;
while (pos < len) { while (pos < len) {
QChar c = txt.at(pos++); QChar c = txt.at(pos++);
if (c.isSpace() || pos - recover > 9) { if (c.isSpace() || pos - recover > 9) {
@ -815,7 +815,7 @@ QString QTextHtmlParser::parseEntity()
++entityLen; ++entityLen;
} }
if (entityLen) { if (entityLen) {
entity = QStringRef(&txt, recover, entityLen); entity = QStringView(txt).mid(recover, entityLen);
QChar resolved = resolveEntity(entity); QChar resolved = resolveEntity(entity);
if (!resolved.isNull()) if (!resolved.isNull())
return QString(resolved); return QString(resolved);
@ -1503,7 +1503,7 @@ static void setWidthAttribute(QTextLength *width, const QString &valueStr)
if (ok) { if (ok) {
*width = QTextLength(QTextLength::FixedLength, realVal); *width = QTextLength(QTextLength::FixedLength, realVal);
} else { } else {
QStringRef value = QStringRef(&valueStr).trimmed(); auto value = QStringView(valueStr).trimmed();
if (!value.isEmpty() && value.endsWith(QLatin1Char('%'))) { if (!value.isEmpty() && value.endsWith(QLatin1Char('%'))) {
value.truncate(value.size() - 1); value.truncate(value.size() - 1);
realVal = value.toDouble(&ok); realVal = value.toDouble(&ok);

View File

@ -497,7 +497,7 @@ QZipReader::FileInfo QZipPrivate::fillFileInfo(int index) const
// fix the file path, if broken (convert separators, eat leading and trailing ones) // fix the file path, if broken (convert separators, eat leading and trailing ones)
fileInfo.filePath = QDir::fromNativeSeparators(fileInfo.filePath); fileInfo.filePath = QDir::fromNativeSeparators(fileInfo.filePath);
QStringRef filePathRef(&fileInfo.filePath); QStringView filePathRef(fileInfo.filePath);
while (filePathRef.startsWith(QLatin1Char('.')) || filePathRef.startsWith(QLatin1Char('/'))) while (filePathRef.startsWith(QLatin1Char('.')) || filePathRef.startsWith(QLatin1Char('/')))
filePathRef = filePathRef.mid(1); filePathRef = filePathRef.mid(1);
while (filePathRef.endsWith(QLatin1Char('/'))) while (filePathRef.endsWith(QLatin1Char('/')))