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:
parent
82a0f4a193
commit
d984adac68
@ -217,7 +217,7 @@ class QIconCacheGtkReader
|
||||
{
|
||||
public:
|
||||
explicit QIconCacheGtkReader(const QString &themeDir);
|
||||
QVector<const char *> lookup(const QStringRef &);
|
||||
QVector<const char *> lookup(QStringView);
|
||||
bool isValid() const { return m_isValid; }
|
||||
private:
|
||||
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.
|
||||
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;
|
||||
if (!isValid() || name.isEmpty())
|
||||
@ -443,7 +443,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
||||
|
||||
const QStringList contentDirs = theme.contentDirs();
|
||||
|
||||
QStringRef iconNameFallback(&iconName);
|
||||
QStringView iconNameFallback(iconName);
|
||||
|
||||
// Iterate through all icon's fallbacks in current theme
|
||||
while (info.entries.isEmpty()) {
|
||||
|
@ -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> text;
|
||||
const auto pairs = description.splitRef(QLatin1String("\n\n"));
|
||||
for (const QStringRef &pair : pairs) {
|
||||
const auto pairs = QStringView{description}.split(u"\n\n");
|
||||
for (const auto &pair : pairs) {
|
||||
int index = pair.indexOf(QLatin1Char(':'));
|
||||
if (index >= 0 && pair.indexOf(QLatin1Char(' ')) < index) {
|
||||
if (!pair.trimmed().isEmpty())
|
||||
text.insert(QLatin1String("Description"), pair.toString().simplified());
|
||||
} else {
|
||||
const QStringRef key = pair.left(index);
|
||||
const auto key = pair.left(index);
|
||||
if (!key.trimmed().isEmpty())
|
||||
text.insert(key.toString(), pair.mid(index + 2).toString().simplified());
|
||||
}
|
||||
|
@ -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();
|
||||
int i = 0;
|
||||
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);
|
||||
|
||||
#ifdef PNG_iTXt_SUPPORTED
|
||||
|
@ -505,8 +505,8 @@ void QHighDpiScaling::updateHighDpiScaling()
|
||||
if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) {
|
||||
int i = 0;
|
||||
const QString spec = qEnvironmentVariable(screenFactorsEnvVar);
|
||||
const auto specs = spec.splitRef(QLatin1Char(';'));
|
||||
for (const QStringRef &spec : specs) {
|
||||
const auto specs = QStringView{spec}.split(u';');
|
||||
for (const auto &spec : specs) {
|
||||
int equalsPos = spec.lastIndexOf(QLatin1Char('='));
|
||||
qreal factor = 0;
|
||||
if (equalsPos > 0) {
|
||||
|
@ -1131,7 +1131,7 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
|
||||
int i = 0;
|
||||
int lastI = 0;
|
||||
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
|
||||
// along the following strategy:
|
||||
// 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
|
||||
QStringRef accelRef(&accel);
|
||||
QStringView accelRef(accel);
|
||||
if(p > 0)
|
||||
accelRef = accelRef.mid(p + 1);
|
||||
|
||||
|
@ -867,10 +867,10 @@ QString QColor::name(NameFormat format) const
|
||||
{
|
||||
switch (format) {
|
||||
case HexRgb:
|
||||
return QLatin1Char('#') + QString::number(rgba() | 0x1000000, 16).rightRef(6);
|
||||
return QLatin1Char('#') + QStringView{QString::number(rgba() | 0x1000000, 16)}.right(6);
|
||||
case HexArgb:
|
||||
// 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();
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ static QPageSize::PageSizeId qt_idForPpdKey(const QString &ppdKey, QSize *match
|
||||
{
|
||||
if (ppdKey.isEmpty())
|
||||
return QPageSize::Custom;
|
||||
QStringRef key(&ppdKey);
|
||||
QStringView key(ppdKey);
|
||||
// Remove any Rotated or Tranverse modifiers
|
||||
if (key.endsWith(QLatin1String("Rotated")))
|
||||
key.chop(7);
|
||||
|
@ -403,14 +403,14 @@ ValueExtractor::ValueExtractor(const QVector<Declaration> &decls, const QPalette
|
||||
LengthData ValueExtractor::lengthValue(const Value& v)
|
||||
{
|
||||
const QString str = v.variant.toString();
|
||||
QStringRef s(&str);
|
||||
QStringView s(str);
|
||||
LengthData data;
|
||||
data.unit = LengthData::None;
|
||||
if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive))
|
||||
if (s.endsWith(u"px", Qt::CaseInsensitive))
|
||||
data.unit = LengthData::Px;
|
||||
else if (s.endsWith(QLatin1String("ex"), Qt::CaseInsensitive))
|
||||
else if (s.endsWith(u"ex", Qt::CaseInsensitive))
|
||||
data.unit = LengthData::Ex;
|
||||
else if (s.endsWith(QLatin1String("em"), Qt::CaseInsensitive))
|
||||
else if (s.endsWith(u"em", Qt::CaseInsensitive))
|
||||
data.unit = LengthData::Em;
|
||||
|
||||
if (data.unit != LengthData::None)
|
||||
@ -1513,7 +1513,7 @@ bool Declaration::realValue(qreal *real, const char *unit) const
|
||||
if (unit && v.type != Value::Length)
|
||||
return false;
|
||||
const QString str = v.variant.toString();
|
||||
QStringRef s(&str);
|
||||
QStringView s(str);
|
||||
if (unit) {
|
||||
const QLatin1String unitStr(unit);
|
||||
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)
|
||||
return false;
|
||||
const QString str = v.variant.toString();
|
||||
QStringRef s(&str);
|
||||
QStringView s(str);
|
||||
if (unit) {
|
||||
const QLatin1String unitStr(unit);
|
||||
if (!s.endsWith(unitStr, Qt::CaseInsensitive))
|
||||
@ -1584,7 +1584,7 @@ QRect Declaration::rectValue() const
|
||||
const QStringList func = v.variant.toStringList();
|
||||
if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0)
|
||||
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)
|
||||
return QRect();
|
||||
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;
|
||||
break;
|
||||
case QCss::AttributeSelector::MatchIncludes: {
|
||||
const auto lst = attrValue.splitRef(QLatin1Char(' '));
|
||||
if (!lst.contains(QStringRef(&a.value)))
|
||||
const auto lst = QStringView{attrValue}.split(u' ');
|
||||
if (!lst.contains(QStringView(a.value)))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
@ -2189,7 +2189,7 @@ QString Scanner::preprocess(const QString &input, bool *hasEscapeSequences)
|
||||
|
||||
hexCount = qMin(hexCount, 6);
|
||||
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) {
|
||||
output.replace(hexStart - 1, hexCount + 1, code);
|
||||
i = hexStart;
|
||||
|
@ -2019,7 +2019,7 @@ size_t qHash(const QFont &font, size_t seed) noexcept
|
||||
*/
|
||||
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 int count = l.count();
|
||||
if (!count || (count > 2 && count < 9) || count > 11 ||
|
||||
|
@ -105,7 +105,7 @@ static int getFontWeight(const QString &weightString)
|
||||
return QFont::Light;
|
||||
if (s == QLatin1String("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 (s2 == QLatin1String("tralight") || s == QLatin1String("tra light"))
|
||||
return QFont::ExtraLight;
|
||||
@ -511,11 +511,11 @@ static QStringList familyList(const QFontDef &req)
|
||||
|
||||
family_list << req.families;
|
||||
if (!req.family.isEmpty()) {
|
||||
const auto list = req.family.splitRef(QLatin1Char(','));
|
||||
const auto list = QStringView{req.family}.split(QLatin1Char(','));
|
||||
const int numFamilies = list.size();
|
||||
family_list.reserve(numFamilies);
|
||||
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('"')))
|
||||
|| (str.startsWith(QLatin1Char('\'')) && str.endsWith(QLatin1Char('\''))))
|
||||
str = str.mid(1, str.length() - 2);
|
||||
|
@ -102,7 +102,7 @@ bool Qt::mightBeRichText(const QString& text)
|
||||
++start;
|
||||
|
||||
// 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()) {
|
||||
if (text.at(start) == QLatin1Char('?')
|
||||
&& start + 2 < text.length()
|
||||
@ -117,12 +117,12 @@ bool Qt::mightBeRichText(const QString& text)
|
||||
++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;
|
||||
int open = start;
|
||||
while (open < text.length() && text.at(open) != QLatin1Char('<')
|
||||
&& 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 <...>
|
||||
++open;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ static bool isValidBlockSeparator(QChar ch)
|
||||
|| ch == QTextEndOfFrame;
|
||||
}
|
||||
|
||||
static bool noBlockInString(const QStringRef &str)
|
||||
static bool noBlockInString(QStringView str)
|
||||
{
|
||||
return !str.contains(QChar::ParagraphSeparator)
|
||||
&& !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)
|
||||
{
|
||||
// ##### optimize when only appending to the fragment!
|
||||
Q_ASSERT(noBlockInString(text.midRef(strPos, length)));
|
||||
Q_ASSERT(noBlockInString(QStringView{text}.mid(strPos, length)));
|
||||
|
||||
split(pos);
|
||||
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)
|
||||
return;
|
||||
|
||||
Q_ASSERT(noBlockInString(QStringRef(&str)));
|
||||
Q_ASSERT(noBlockInString(str));
|
||||
|
||||
int strPos = text.length();
|
||||
text.append(str);
|
||||
@ -497,7 +497,7 @@ int QTextDocumentPrivate::remove_string(int pos, uint length, QTextUndoCommand::
|
||||
|
||||
Q_ASSERT(blocks.size(b) > 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);
|
||||
|
||||
@ -632,7 +632,7 @@ void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::O
|
||||
|
||||
if (key+1 != blocks.position(b)) {
|
||||
// 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);
|
||||
|
||||
if (needsInsert) {
|
||||
|
@ -2979,7 +2979,7 @@ static QString stringMidRetainingBidiCC(const QString &string,
|
||||
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
|
||||
@ -3154,7 +3154,7 @@ QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int
|
||||
if (prevCharJoins(layoutData->string, rightPos))
|
||||
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);
|
||||
|
@ -328,17 +328,17 @@ bool operator<(const QTextHtmlEntity &entity1, const QTextHtmlEntity &entity2)
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool operator<(const QStringRef &entityStr, const QTextHtmlEntity &entity)
|
||||
static bool operator<(QStringView entityStr, const QTextHtmlEntity &entity)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static QChar resolveEntity(const QStringRef &entity)
|
||||
static QChar resolveEntity(QStringView entity)
|
||||
{
|
||||
const QTextHtmlEntity *start = &entities[0];
|
||||
const QTextHtmlEntity *end = &entities[MAX_ENTITY];
|
||||
@ -804,7 +804,7 @@ QString QTextHtmlParser::parseEntity()
|
||||
{
|
||||
const int recover = pos;
|
||||
int entityLen = 0;
|
||||
QStringRef entity;
|
||||
QStringView entity;
|
||||
while (pos < len) {
|
||||
QChar c = txt.at(pos++);
|
||||
if (c.isSpace() || pos - recover > 9) {
|
||||
@ -815,7 +815,7 @@ QString QTextHtmlParser::parseEntity()
|
||||
++entityLen;
|
||||
}
|
||||
if (entityLen) {
|
||||
entity = QStringRef(&txt, recover, entityLen);
|
||||
entity = QStringView(txt).mid(recover, entityLen);
|
||||
QChar resolved = resolveEntity(entity);
|
||||
if (!resolved.isNull())
|
||||
return QString(resolved);
|
||||
@ -1503,7 +1503,7 @@ static void setWidthAttribute(QTextLength *width, const QString &valueStr)
|
||||
if (ok) {
|
||||
*width = QTextLength(QTextLength::FixedLength, realVal);
|
||||
} else {
|
||||
QStringRef value = QStringRef(&valueStr).trimmed();
|
||||
auto value = QStringView(valueStr).trimmed();
|
||||
if (!value.isEmpty() && value.endsWith(QLatin1Char('%'))) {
|
||||
value.truncate(value.size() - 1);
|
||||
realVal = value.toDouble(&ok);
|
||||
|
@ -497,7 +497,7 @@ QZipReader::FileInfo QZipPrivate::fillFileInfo(int index) const
|
||||
|
||||
// fix the file path, if broken (convert separators, eat leading and trailing ones)
|
||||
fileInfo.filePath = QDir::fromNativeSeparators(fileInfo.filePath);
|
||||
QStringRef filePathRef(&fileInfo.filePath);
|
||||
QStringView filePathRef(fileInfo.filePath);
|
||||
while (filePathRef.startsWith(QLatin1Char('.')) || filePathRef.startsWith(QLatin1Char('/')))
|
||||
filePathRef = filePathRef.mid(1);
|
||||
while (filePathRef.endsWith(QLatin1Char('/')))
|
||||
|
Loading…
x
Reference in New Issue
Block a user