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>
This commit is contained in:
Karsten Heimrich 2020-06-16 10:23:19 +02:00
parent b65eee0390
commit 1b10ce6a08
74 changed files with 341 additions and 342 deletions

View File

@ -257,7 +257,7 @@ void QWavefrontMesh::readData()
while (!stream.atEnd()) {
stream.readLineInto(&buffer);
QVector<QStringRef> tokens = buffer.splitRef(space, Qt::SkipEmptyParts);
auto tokens = QStringView{buffer}.split(space, Qt::SkipEmptyParts);
if (tokens.size() < 2)
continue;
@ -316,7 +316,7 @@ void QWavefrontMesh::readData()
if (tokens.size() >= 4 && tokens.size() <= 5) {
{
bool ok;
QVector<QStringRef> faceTokens = tokens.at(1).split(slash, Qt::SkipEmptyParts);
auto faceTokens = tokens.at(1).split(slash, Qt::SkipEmptyParts);
Q_ASSERT(!faceTokens.isEmpty());
p1 = faceTokens.at(0).toInt(&ok) - 1;
@ -336,7 +336,7 @@ void QWavefrontMesh::readData()
{
bool ok;
QVector<QStringRef> faceTokens = tokens.at(2).split(slash, Qt::SkipEmptyParts);
auto faceTokens = tokens.at(2).split(slash, Qt::SkipEmptyParts);
Q_ASSERT(!faceTokens.isEmpty());
p2 = faceTokens.at(0).toInt(&ok) - 1;
@ -356,7 +356,7 @@ void QWavefrontMesh::readData()
{
bool ok;
QVector<QStringRef> faceTokens = tokens.at(3).split(slash, Qt::SkipEmptyParts);
auto faceTokens = tokens.at(3).split(slash, Qt::SkipEmptyParts);
Q_ASSERT(!faceTokens.isEmpty());
p3 = faceTokens.at(0).toInt(&ok) - 1;
@ -394,7 +394,7 @@ void QWavefrontMesh::readData()
if (tokens.size() == 5) {
bool ok;
QVector<QStringRef> faceTokens = tokens.at(4).split(slash, Qt::SkipEmptyParts);
auto faceTokens = tokens.at(4).split(slash, Qt::SkipEmptyParts);
Q_ASSERT(!faceTokens.isEmpty());
int p4 = faceTokens.at(0).toInt(&ok) - 1;

View File

@ -722,7 +722,7 @@ bool QQmlEngineDebugServiceImpl::resetBinding(int objectId, const QString &prope
QQmlContext *context = qmlContext(object);
if (object && context && context->isValid()) {
QStringRef parentPropertyRef(&propertyName);
QStringView parentPropertyRef(propertyName);
const int idx = parentPropertyRef.indexOf(QLatin1Char('.'));
if (idx != -1)
parentPropertyRef = parentPropertyRef.left(idx);

View File

@ -183,9 +183,9 @@ QQmlNativeDebugConnector::QQmlNativeDebugConnector()
: m_blockingMode(false)
{
const QString args = commandLineArguments();
const auto lstjsDebugArguments = args.splitRef(QLatin1Char(','), Qt::SkipEmptyParts);
const auto lstjsDebugArguments = QStringView{args}.split(QLatin1Char(','), Qt::SkipEmptyParts);
QStringList services;
for (const QStringRef &strArgument : lstjsDebugArguments) {
for (const QStringView &strArgument : lstjsDebugArguments) {
if (strArgument == QLatin1String("block")) {
m_blockingMode = true;
} else if (strArgument == QLatin1String("native")) {

View File

@ -345,9 +345,9 @@ void QQmlDebugServerImpl::parseArguments()
QString fileName;
QStringList services;
const auto lstjsDebugArguments = args.splitRef(QLatin1Char(','), Qt::SkipEmptyParts);
const auto lstjsDebugArguments = QStringView{args}.split(QLatin1Char(','), Qt::SkipEmptyParts);
for (auto argsIt = lstjsDebugArguments.begin(), argsItEnd = lstjsDebugArguments.end(); argsIt != argsItEnd; ++argsIt) {
const QStringRef &strArgument = *argsIt;
const QStringView &strArgument = *argsIt;
if (strArgument.startsWith(QLatin1String("port:"))) {
portFrom = strArgument.mid(5).toInt(&ok);
portTo = portFrom;

View File

@ -105,9 +105,9 @@ public:
template <typename Tp, typename... Ta> Tp *New(Ta... args)
{ return new (this->allocate(sizeof(Tp))) Tp(args...); }
QStringRef newString(const QString &string) {
QStringView newString(const QString &string) {
strings.append(new QString(string));
return QStringRef(strings.last());
return QStringView(*strings.last());
}
private:

View File

@ -407,7 +407,7 @@ void ScriptDirectivesCollector::importModule(const QString &uri, const QString &
QV4::CompiledData::Import *import = engine->pool()->New<QV4::CompiledData::Import>();
import->type = QV4::CompiledData::Import::ImportLibrary;
import->uriIndex = jsGenerator->registerString(uri);
import->version = IRBuilder::extractVersion(QStringRef(&version));
import->version = IRBuilder::extractVersion(QStringView(version));
import->qualifierIndex = jsGenerator->registerString(module);
import->location.line = lineNumber;
import->location.column = column;
@ -526,7 +526,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiObjectDefinition *node)
QQmlJS::AST::UiQualifiedId *lastId = node->qualifiedTypeNameId;
while (lastId->next)
lastId = lastId->next;
bool isType = lastId->name.unicode()->isUpper();
bool isType = lastId->name.data()->isUpper();
if (isType) {
int idx = 0;
if (!defineQMLObject(&idx, node))
@ -915,7 +915,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node)
if (memberType == QLatin1String("alias")) {
return appendAlias(node);
} else {
const QStringRef &name = node->name;
const QStringView &name = node->name;
Property *property = New<Property>();
property->isReadOnly = node->isReadonlyMember;
@ -927,7 +927,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node)
property->setBuiltinType(builtinPropertyType);
if (!typeFound && memberType.at(0).isUpper()) {
const QStringRef &typeModifier = node->typeModifier;
const QStringView &typeModifier = node->typeModifier;
property->setCustomType(registerString(memberType));
if (typeModifier == QLatin1String("list")) {
@ -1043,15 +1043,15 @@ QString IRBuilder::asString(QQmlJS::AST::UiQualifiedId *node)
return s;
}
QStringRef IRBuilder::asStringRef(QQmlJS::AST::Node *node)
QStringView IRBuilder::asStringRef(QQmlJS::AST::Node *node)
{
if (!node)
return QStringRef();
return QStringView();
return textRefAt(node->firstSourceLocation(), node->lastSourceLocation());
}
QTypeRevision IRBuilder::extractVersion(const QStringRef &string)
QTypeRevision IRBuilder::extractVersion(QStringView string)
{
if (string.isEmpty())
return QTypeRevision();
@ -1062,9 +1062,9 @@ QTypeRevision IRBuilder::extractVersion(const QStringRef &string)
: QTypeRevision::fromVersion(string.left(dot).toInt(), string.mid(dot + 1).toInt());
}
QStringRef IRBuilder::textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const
QStringView IRBuilder::textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const
{
return QStringRef(&sourceCode, first.offset, last.offset + last.length - first.offset);
return QStringView(sourceCode).mid(first.offset, last.offset + last.length - first.offset);
}
void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST::Statement *statement, QQmlJS::AST::Node *parentNode)
@ -1127,7 +1127,7 @@ void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST
}
}
void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::ArgumentList *args, QV4::CompiledData::Binding *binding)
void IRBuilder::tryGeneratingTranslationBinding(QStringView base, AST::ArgumentList *args, QV4::CompiledData::Binding *binding)
{
if (base == QLatin1String("qsTr")) {
QV4::CompiledData::TranslationData translationData;
@ -1138,7 +1138,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg
if (!args || !args->expression)
return; // no arguments, stop
QStringRef translation;
QStringView translation;
if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(args->expression)) {
translation = arg1->value;
} else {
@ -1179,7 +1179,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg
if (!args || !args->expression)
return; // no arguments, stop
QStringRef id;
QStringView id;
if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(args->expression)) {
id = arg1->value;
} else {
@ -1207,7 +1207,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg
if (!args || !args->expression)
return; // no arguments, stop
QStringRef str;
QStringView str;
if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(args->expression)) {
str = arg1->value;
} else {
@ -1228,7 +1228,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg
if (!args || !args->expression)
return; // no second arguments, stop
QStringRef str;
QStringView str;
if (QQmlJS::AST::StringLiteral *arg2 = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(args->expression)) {
str = arg2->value;
} else {
@ -1408,7 +1408,7 @@ Object *IRBuilder::bindingsTarget() const
bool IRBuilder::setId(const QQmlJS::SourceLocation &idLocation, QQmlJS::AST::Statement *value)
{
QQmlJS::SourceLocation loc = value->firstSourceLocation();
QStringRef str;
QStringView str;
QQmlJS::AST::Node *node = value;
if (QQmlJS::AST::ExpressionStatement *stmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(node)) {
@ -1433,7 +1433,7 @@ bool IRBuilder::setId(const QQmlJS::SourceLocation &idLocation, QQmlJS::AST::Sta
if (!ch.isLetter() && ch != u)
COMPILE_EXCEPTION(loc, tr( "IDs must start with a letter or underscore"));
for (int ii = 1; ii < str.count(); ++ii) {
for (int ii = 1; ii < str.size(); ++ii) {
ch = str.at(ii);
if (!ch.isLetterOrNumber() && ch != u)
COMPILE_EXCEPTION(loc, tr( "IDs must contain only letters, numbers, and underscores"));
@ -1469,7 +1469,7 @@ bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, O
qualifiedIdElement = qualifiedIdElement->next;
currentName += QLatin1Char('.') + qualifiedIdElement->name;
if (!qualifiedIdElement->name.unicode()->isUpper())
if (!qualifiedIdElement->name.data()->isUpper())
COMPILE_EXCEPTION(qualifiedIdElement->firstSourceLocation(), tr("Expected type name"));
break;
@ -1479,7 +1479,7 @@ bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, O
*object = _object;
while (qualifiedIdElement->next) {
const quint32 propertyNameIndex = registerString(currentName);
const bool isAttachedProperty = qualifiedIdElement->name.unicode()->isUpper();
const bool isAttachedProperty = qualifiedIdElement->name.data()->isUpper();
Binding *binding = (*object)->findBinding(propertyNameIndex);
if (binding) {

View File

@ -497,16 +497,16 @@ public:
{ return defineQMLObject(objectIndex, node->qualifiedTypeNameId, node->qualifiedTypeNameId->firstSourceLocation(), node->initializer, declarationsOverride); }
static QString asString(QQmlJS::AST::UiQualifiedId *node);
QStringRef asStringRef(QQmlJS::AST::Node *node);
static QTypeRevision extractVersion(const QStringRef &string);
QStringRef textRefAt(const QQmlJS::SourceLocation &loc) const
{ return QStringRef(&sourceCode, loc.offset, loc.length); }
QStringRef textRefAt(const QQmlJS::SourceLocation &first,
QStringView asStringRef(QQmlJS::AST::Node *node);
static QTypeRevision extractVersion(QStringView string);
QStringView textRefAt(const QQmlJS::SourceLocation &loc) const
{ return QStringView(sourceCode).mid(loc.offset, loc.length); }
QStringView textRefAt(const QQmlJS::SourceLocation &first,
const QQmlJS::SourceLocation &last) const;
void setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST::Statement *statement,
QQmlJS::AST::Node *parentNode);
void tryGeneratingTranslationBinding(const QStringRef &base, QQmlJS::AST::ArgumentList *args, QV4::CompiledData::Binding *binding);
void tryGeneratingTranslationBinding(QStringView base, QQmlJS::AST::ArgumentList *args, QV4::CompiledData::Binding *binding);
void appendBinding(QQmlJS::AST::UiQualifiedId *name, QQmlJS::AST::Statement *value,
QQmlJS::AST::Node *parentNode);

View File

@ -3969,14 +3969,14 @@ public:
}
private:
void collectIdentifiers(QVector<QStringView> &ids, AST::Node *node) {
void collectIdentifiers(QList<QStringView> &ids, AST::Node *node) {
class Collector: public QQmlJS::AST::Visitor {
private:
QVector<QStringView> &ids;
QList<QStringView> &ids;
VolatileMemoryLocationScanner *parent;
public:
Collector(QVector<QStringView> &ids, VolatileMemoryLocationScanner *parent) :
Collector(QList<QStringView> &ids, VolatileMemoryLocationScanner *parent) :
QQmlJS::AST::Visitor(parent->recursionDepth()), ids(ids), parent(parent)
{}

View File

@ -105,15 +105,15 @@ public:
class VolatileMemoryLocations {
friend VolatileMemoryLocationScanner;
bool allVolatile = false;
QVector<QStringView> specificLocations;
QList<QStringView> specificLocations;
public:
bool isVolatile(const QStringView &name) {
bool isVolatile(QStringView name) {
if (allVolatile)
return true;
return specificLocations.contains(name);
}
void add(const QStringRef &name) { if (!allVolatile) specificLocations.append(name); }
void add(QStringView name) { if (!allVolatile) specificLocations.append(name); }
void setAllVolatile() { allVolatile = true; }
};
class RValue {

View File

@ -115,7 +115,7 @@ void ScanFunctions::checkDirectivePrologue(StatementList *ast)
// allowed.
if (strLit->literalToken.length < 2)
continue;
QStringRef str = _sourceCode.midRef(strLit->literalToken.offset + 1, strLit->literalToken.length - 2);
QStringView str = QStringView{_sourceCode}.mid(strLit->literalToken.offset + 1, strLit->literalToken.length - 2);
if (str == QLatin1String("use strict")) {
_context->isStrict = true;
} else {
@ -129,7 +129,7 @@ void ScanFunctions::checkDirectivePrologue(StatementList *ast)
}
}
void ScanFunctions::checkName(const QStringRef &name, const QQmlJS::SourceLocation &loc)
void ScanFunctions::checkName(QStringView name, const QQmlJS::SourceLocation &loc)
{
if (_context->isStrict) {
if (name == QLatin1String("implements")
@ -337,7 +337,7 @@ bool ScanFunctions::visit(PatternElement *ast)
for (const auto &name : qAsConst(names)) {
if (_context->isStrict && (name.id == QLatin1String("eval") || name.id == QLatin1String("arguments")))
_cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Variable name may not be eval or arguments in strict mode"));
checkName(QStringRef(&name.id), ast->identifierToken);
checkName(QStringView(name.id), ast->identifierToken);
if (name.id == QLatin1String("arguments"))
_context->usesArgumentsObject = Context::ArgumentsObjectNotUsed;
if (ast->scope == VariableScope::Const && !ast->initializer && !ast->isForDeclaration && !ast->destructuringPattern()) {
@ -376,7 +376,7 @@ bool ScanFunctions::visit(ExpressionStatement *ast)
return false;
} else {
SourceLocation firstToken = ast->firstSourceLocation();
if (_sourceCode.midRef(firstToken.offset, firstToken.length) == QLatin1String("function")) {
if (QStringView{_sourceCode}.mid(firstToken.offset, firstToken.length) == QLatin1String("function")) {
_cg->throwSyntaxError(firstToken, QStringLiteral("unexpected token"));
}
}

View File

@ -97,7 +97,7 @@ protected:
void checkDirectivePrologue(QQmlJS::AST::StatementList *ast);
void checkName(const QStringRef &name, const QQmlJS::SourceLocation &loc);
void checkName(QStringView name, const QQmlJS::SourceLocation &loc);
bool visit(QQmlJS::AST::Program *ast) override;
void endVisit(QQmlJS::AST::Program *) override;

View File

@ -839,8 +839,8 @@ QString ExecutableCompilationUnit::bindingValueAsString(const CompiledData::Bind
// This code must match that in the qsTr() implementation
const QString &path = fileName();
int lastSlash = path.lastIndexOf(QLatin1Char('/'));
QStringRef context = (lastSlash > -1) ? path.midRef(lastSlash + 1, path.length() - lastSlash - 5)
: QStringRef();
QStringView context = (lastSlash > -1) ? QStringView{path}.mid(lastSlash + 1, path.length() - lastSlash - 5)
: QStringView();
QByteArray contextUtf8 = context.toUtf8();
QByteArray comment = stringAt(translation.commentIndex).toUtf8();
QByteArray text = stringAt(translation.stringIndex).toUtf8();

View File

@ -198,7 +198,7 @@ Heap::FunctionObject *FunctionObject::createBuiltinFunction(ExecutionEngine *eng
Scope scope(engine);
ScopedString name(scope, nameOrSymbol);
if (!name)
name = engine->newString(QChar::fromLatin1('[') + nameOrSymbol->toQString().midRef(1) + QChar::fromLatin1(']'));
name = engine->newString(QChar::fromLatin1('[') + QStringView{nameOrSymbol->toQString()}.mid(1) + QChar::fromLatin1(']'));
ScopedFunctionObject function(scope, engine->memoryManager->allocate<FunctionObject>(engine->rootContext(), name, code));
function->defineReadonlyConfigurableProperty(engine->id_length(), Value::fromInt32(argumentCount));

View File

@ -304,7 +304,7 @@ static QString decode(const QString &input, DecodeMode decodeMode, bool *ok)
++r;
}
if (*r)
output.append(input.midRef(start, i - start + 1));
output.append(QStringView{input}.mid(start, i - start + 1));
else
output.append(QChar(b));
} else {

View File

@ -177,7 +177,7 @@ void Object::defineAccessorProperty(StringOrSymbol *name, VTable::Call getter, V
ScopedProperty p(scope);
QString n = name->toQString();
if (n.at(0) == QLatin1Char('@'))
n = QChar::fromLatin1('[') + n.midRef(1) + QChar::fromLatin1(']');
n = QChar::fromLatin1('[') + QStringView{n}.mid(1) + QChar::fromLatin1(']');
if (getter) {
ScopedString getName(scope, v4->newString(QString::fromLatin1("get ") + n));
p->setGetter(ScopedFunctionObject(scope, FunctionObject::createBuiltinFunction(v4, getName, getter, 0)));

View File

@ -103,7 +103,7 @@ QV4::Heap::String *QV4::PropertyKey::asFunctionName(ExecutionEngine *engine, Fun
if (s->internalClass->vtable->isString)
n += s->toQString();
else if (str.length() > 1)
n += QChar::fromLatin1('[') + str.midRef(1) + QChar::fromLatin1(']');
n += QChar::fromLatin1('[') + QStringView{str}.mid(1) + QChar::fromLatin1(']');
}
return engine->newString(n);
}

View File

@ -726,12 +726,12 @@ ReturnedValue RegExpPrototype::method_replace(const FunctionObject *f, const Val
if (scope.hasException())
return Encode::undefined();
if (position >= nextSourcePosition) {
accumulatedResult += s->toQString().midRef(nextSourcePosition, position - nextSourcePosition) + replacement;
accumulatedResult += QStringView{s->toQString()}.mid(nextSourcePosition, position - nextSourcePosition) + replacement;
nextSourcePosition = position + matchLength;
}
}
if (nextSourcePosition < lengthS) {
accumulatedResult += s->toQString().midRef(nextSourcePosition);
accumulatedResult += QStringView{s->toQString()}.mid(nextSourcePosition);
}
return scope.engine->newString(accumulatedResult)->asReturnedValue();
}

View File

@ -417,7 +417,7 @@ double RuntimeHelpers::stringToNumber(const QString &string)
if (string.length() > excessiveLength)
return qQNaN();
const QStringRef s = QStringRef(&string).trimmed();
const QStringView s = QStringView(string).trimmed();
if (s.startsWith(QLatin1Char('0'))) {
int base = -1;
if (s.startsWith(QLatin1String("0x")) || s.startsWith(QLatin1String("0X")))

View File

@ -96,7 +96,7 @@ void Script::parse()
if (sourceCode.startsWith(QLatin1String("function("))) {
static const int snippetLength = 70;
qWarning() << "Warning: Using function expressions as statements in scripts is not compliant with the ECMAScript specification:\n"
<< (sourceCode.leftRef(snippetLength) + QLatin1String("..."))
<< (QStringView{sourceCode}.left(snippetLength) + QLatin1String("..."))
<< "\nThis will throw a syntax error in Qt 5.12. If you want a function expression, surround it by parentheses.";
}

View File

@ -464,7 +464,7 @@ ReturnedValue StringPrototype::method_endsWith(const FunctionObject *b, const Va
if (pos == value.length())
RETURN_RESULT(Encode(value.endsWith(searchString)));
QStringRef stringToSearch = value.leftRef(pos);
QStringView stringToSearch = QStringView{value}.left(pos);
return Encode(stringToSearch.endsWith(searchString));
}
@ -514,7 +514,7 @@ ReturnedValue StringPrototype::method_includes(const FunctionObject *b, const Va
if (pos == 0)
RETURN_RESULT(Encode(value.contains(searchString)));
QStringRef stringToSearch = value.midRef(pos);
QStringView stringToSearch = QStringView{value}.mid(pos);
return Encode(stringToSearch.contains(searchString));
}
@ -765,7 +765,7 @@ static void appendReplacementString(QString *result, const QString &input, const
}
i += skip;
if (substStart != JSC::Yarr::offsetNoMatch && substEnd != JSC::Yarr::offsetNoMatch)
*result += input.midRef(substStart, substEnd - substStart);
*result += QStringView{input}.mid(substStart, substEnd - substStart);
else if (skip == 0) // invalid capture reference. Taken as literal value
*result += replaceValue.at(i);
} else {
@ -863,11 +863,11 @@ ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Val
Value that = Value::undefinedValue();
replacement = searchCallback->call(&that, arguments, numCaptures + 2);
CHECK_EXCEPTION();
result += string.midRef(lastEnd, matchStart - lastEnd);
result += QStringView{string}.mid(lastEnd, matchStart - lastEnd);
result += replacement->toQString();
lastEnd = matchEnd;
}
result += string.midRef(lastEnd);
result += QStringView{string}.mid(lastEnd);
} else {
QString newString = replaceValue->toQString();
result.reserve(string.length() + numStringMatches*newString.size());
@ -880,11 +880,11 @@ ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Val
if (matchStart == JSC::Yarr::offsetNoMatch)
continue;
result += string.midRef(lastEnd, matchStart - lastEnd);
result += QStringView{string}.mid(lastEnd, matchStart - lastEnd);
appendReplacementString(&result, string, newString, matchOffsets + baseIndex, numCaptures);
lastEnd = matchEnd;
}
result += string.midRef(lastEnd);
result += QStringView{string}.mid(lastEnd);
}
if (matchOffsets != _matchOffsets)
@ -1052,7 +1052,7 @@ ReturnedValue StringPrototype::method_startsWith(const FunctionObject *b, const
if (pos == 0)
return Encode(value.startsWith(searchString));
QStringRef stringToSearch = value.midRef(pos);
QStringView stringToSearch = QStringView{value}.mid(pos);
RETURN_RESULT(Encode(stringToSearch.startsWith(searchString)));
}

View File

@ -182,5 +182,5 @@ Heap::Symbol *Symbol::create(ExecutionEngine *e, const QString &s)
QString Symbol::descriptiveString() const
{
return QLatin1String("Symbol(") + toQString().midRef(1) + QLatin1String(")");
return QLatin1String("Symbol(") + QStringView{toQString()}.mid(1) + QLatin1String(")");
}

View File

@ -403,10 +403,10 @@ protected:
inline Value &sym(int index)
{ return sym_stack [tos + index - 1]; }
inline QStringRef &stringRef(int index)
inline QStringView &stringRef(int index)
{ return string_stack [tos + index - 1]; }
inline QStringRef &rawStringRef(int index)
inline QStringView &rawStringRef(int index)
{ return rawString_stack [tos + index - 1]; }
inline SourceLocation &loc(int index)
@ -444,8 +444,8 @@ protected:
Value *sym_stack = nullptr;
int *state_stack = nullptr;
SourceLocation *location_stack = nullptr;
QVector<QStringRef> string_stack;
QVector<QStringRef> rawString_stack;
QList<QStringView> string_stack;
QList<QStringView> rawString_stack;
AST::Node *program = nullptr;
@ -456,14 +456,14 @@ protected:
int token;
double dval;
SourceLocation loc;
QStringRef spell;
QStringRef raw;
QStringView spell;
QStringView raw;
};
int yytoken = -1;
double yylval = 0.;
QStringRef yytokenspell;
QStringRef yytokenraw;
QStringView yytokenspell;
QStringView yytokenraw;
SourceLocation yylloc;
SourceLocation yyprevlloc;
@ -555,7 +555,7 @@ static inline SourceLocation location(Lexer *lexer)
AST::UiQualifiedId *Parser::reparseAsQualifiedId(AST::ExpressionNode *expr)
{
QVarLengthArray<QStringRef, 4> nameIds;
QVarLengthArray<QStringView, 4> nameIds;
QVarLengthArray<SourceLocation, 4> locations;
AST::ExpressionNode *it = expr;
@ -3613,7 +3613,7 @@ ContinueStatement: T_CONTINUE IdentifierReference Semicolon;
BreakStatement: T_BREAK Semicolon;
/.
case $rule_number: {
AST::BreakStatement *node = new (pool) AST::BreakStatement(QStringRef());
AST::BreakStatement *node = new (pool) AST::BreakStatement(QStringView());
node->breakToken = loc(1);
node->semicolonToken = loc(2);
sym(1).Node = node;
@ -3887,7 +3887,7 @@ FunctionDeclaration_Default: Function T_LPAREN FormalParameters T_RPAREN TypeAnn
case $rule_number: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false;
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(7).StatementList,
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(7).StatementList,
/*type annotation*/nullptr);
node->functionToken = loc(1);
node->lparenToken = loc(2);
@ -3921,7 +3921,7 @@ FunctionExpression: T_FUNCTION T_LPAREN FormalParameters T_RPAREN TypeAnnotation
case $rule_number: {
if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList))
return false;
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringRef(), sym(3).FormalParameterList, sym(7).StatementList,
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(7).StatementList,
/*type annotation*/nullptr);
node->functionToken = loc(1);
node->lparenToken = loc(2);
@ -4011,7 +4011,7 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead AssignmentExpress
ret->returnToken = sym(4).Node->firstSourceLocation();
ret->semicolonToken = sym(4).Node->lastSourceLocation();
AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish();
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringRef(), sym(1).FormalParameterList, statements);
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements);
f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1);
f->lbraceToken = sym(4).Node->firstSourceLocation();
@ -4025,7 +4025,7 @@ ArrowFunction: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK Functi
ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK FunctionLBrace FunctionBody FunctionRBrace;
/.
case $rule_number: {
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringRef(), sym(1).FormalParameterList, sym(6).StatementList);
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, sym(6).StatementList);
f->isArrowFunction = true;
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1);
f->lbraceToken = loc(6);
@ -4186,7 +4186,7 @@ GeneratorDeclaration_Default: GeneratorDeclaration;
GeneratorDeclaration_Default: FunctionStar GeneratorLParen FormalParameters T_RPAREN FunctionLBrace GeneratorBody GeneratorRBrace;
/.
case $rule_number: {
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList);
AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
@ -4216,7 +4216,7 @@ GeneratorExpression: T_FUNCTION_STAR BindingIdentifier GeneratorLParen FormalPar
GeneratorExpression: T_FUNCTION_STAR GeneratorLParen FormalParameters T_RPAREN FunctionLBrace GeneratorBody GeneratorRBrace;
/.
case $rule_number: {
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList);
AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(6).StatementList);
node->functionToken = loc(1);
node->lparenToken = loc(2);
node->rparenToken = loc(4);
@ -4291,7 +4291,7 @@ ClassExpression: T_CLASS BindingIdentifier ClassHeritageOpt ClassLBrace ClassBod
ClassDeclaration_Default: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt ClassRBrace;
/.
case $rule_number: {
AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(QStringRef(), sym(2).Expression, sym(4).ClassElementList);
AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(QStringView(), sym(2).Expression, sym(4).ClassElementList);
node->classToken = loc(1);
node->lbraceToken = loc(3);
node->rbraceToken = loc(5);
@ -4302,7 +4302,7 @@ ClassDeclaration_Default: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt Clas
ClassExpression: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt ClassRBrace;
/.
case $rule_number: {
AST::ClassExpression *node = new (pool) AST::ClassExpression(QStringRef(), sym(2).Expression, sym(4).ClassElementList);
AST::ClassExpression *node = new (pool) AST::ClassExpression(QStringView(), sym(2).Expression, sym(4).ClassElementList);
node->classToken = loc(1);
node->lbraceToken = loc(3);
node->rbraceToken = loc(5);

View File

@ -335,11 +335,11 @@ class QML_PARSER_EXPORT UiQualifiedId: public Node
public:
QQMLJS_DECLARE_AST_NODE(UiQualifiedId)
UiQualifiedId(const QStringRef &name)
UiQualifiedId(QStringView name)
: next(this), name(name)
{ kind = K; }
UiQualifiedId(UiQualifiedId *previous, const QStringRef &name)
UiQualifiedId(UiQualifiedId *previous, QStringView name)
: name(name)
{
kind = K;
@ -364,7 +364,7 @@ public:
// attributes
UiQualifiedId *next;
QStringRef name;
QStringView name;
SourceLocation identifierToken;
};
@ -549,7 +549,7 @@ class QML_PARSER_EXPORT IdentifierExpression: public LeftHandSideExpression
public:
QQMLJS_DECLARE_AST_NODE(IdentifierExpression)
IdentifierExpression(const QStringRef &n):
IdentifierExpression(QStringView n):
name (n) { kind = K; }
void accept0(BaseVisitor *visitor) override;
@ -561,7 +561,7 @@ public:
{ return identifierToken; }
// attributes
QStringRef name;
QStringView name;
SourceLocation identifierToken;
};
@ -698,7 +698,7 @@ class QML_PARSER_EXPORT StringLiteral : public LeftHandSideExpression
public:
QQMLJS_DECLARE_AST_NODE(StringLiteral)
StringLiteral(const QStringRef &v):
StringLiteral(QStringView v):
value (v) { kind = K; }
void accept0(BaseVisitor *visitor) override;
@ -710,7 +710,7 @@ public:
{ return literalToken; }
// attributes:
QStringRef value;
QStringView value;
SourceLocation literalToken;
};
@ -719,7 +719,7 @@ class QML_PARSER_EXPORT TemplateLiteral : public LeftHandSideExpression
public:
QQMLJS_DECLARE_AST_NODE(TemplateLiteral)
TemplateLiteral(const QStringRef &str, const QStringRef &raw, ExpressionNode *e)
TemplateLiteral(QStringView str, QStringView raw, ExpressionNode *e)
: value(str), rawValue(raw), expression(e), next(nullptr)
{ kind = K; }
@ -734,8 +734,8 @@ public:
void accept0(BaseVisitor *visitor) override;
QStringRef value;
QStringRef rawValue;
QStringView value;
QStringView rawValue;
ExpressionNode *expression;
TemplateLiteral *next;
SourceLocation literalToken;
@ -746,7 +746,7 @@ class QML_PARSER_EXPORT RegExpLiteral: public LeftHandSideExpression
public:
QQMLJS_DECLARE_AST_NODE(RegExpLiteral)
RegExpLiteral(const QStringRef &p, int f):
RegExpLiteral(QStringView p, int f):
pattern (p), flags (f) { kind = K; }
void accept0(BaseVisitor *visitor) override;
@ -758,7 +758,7 @@ public:
{ return literalToken; }
// attributes:
QStringRef pattern;
QStringView pattern;
int flags;
SourceLocation literalToken;
};
@ -937,7 +937,7 @@ public:
: initializer(i), type(t)
{ kind = K; }
PatternElement(const QStringRef &n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding)
PatternElement(QStringView n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding)
: bindingIdentifier(n), initializer(i), type(t)
, typeAnnotation(typeAnnotation)
{
@ -973,7 +973,7 @@ public:
// attributes
SourceLocation identifierToken;
QStringRef bindingIdentifier;
QStringView bindingIdentifier;
ExpressionNode *bindingTarget = nullptr;
ExpressionNode *initializer = nullptr;
Type type = Literal;
@ -1032,7 +1032,7 @@ public:
: PatternElement(i, t), name(name)
{ kind = K; }
PatternProperty(PropertyName *name, const QStringRef &n, ExpressionNode *i = nullptr)
PatternProperty(PropertyName *name, QStringView n, ExpressionNode *i = nullptr)
: PatternElement(n, /*type annotation*/nullptr, i), name(name)
{ kind = K; }
@ -1102,7 +1102,7 @@ class QML_PARSER_EXPORT IdentifierPropertyName: public PropertyName
public:
QQMLJS_DECLARE_AST_NODE(IdentifierPropertyName)
IdentifierPropertyName(const QStringRef &n):
IdentifierPropertyName(QStringView n):
id (n) { kind = K; }
void accept0(BaseVisitor *visitor) override;
@ -1110,7 +1110,7 @@ public:
QString asString() const override { return id.toString(); }
// attributes
QStringRef id;
QStringView id;
};
class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName
@ -1118,7 +1118,7 @@ class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName
public:
QQMLJS_DECLARE_AST_NODE(StringLiteralPropertyName)
StringLiteralPropertyName(const QStringRef &n):
StringLiteralPropertyName(QStringView n):
id (n) { kind = K; }
void accept0(BaseVisitor *visitor) override;
@ -1126,7 +1126,7 @@ public:
QString asString() const override { return id.toString(); }
// attributes
QStringRef id;
QStringView id;
};
class QML_PARSER_EXPORT NumericLiteralPropertyName: public PropertyName
@ -1198,7 +1198,7 @@ class QML_PARSER_EXPORT FieldMemberExpression: public LeftHandSideExpression
public:
QQMLJS_DECLARE_AST_NODE(FieldMemberExpression)
FieldMemberExpression(ExpressionNode *b, const QStringRef &n):
FieldMemberExpression(ExpressionNode *b, QStringView n):
base (b), name (n)
{ kind = K; }
@ -1212,7 +1212,7 @@ public:
// attributes
ExpressionNode *base;
QStringRef name;
QStringView name;
SourceLocation dotToken;
SourceLocation identifierToken;
};
@ -1988,7 +1988,7 @@ class QML_PARSER_EXPORT ContinueStatement: public Statement
public:
QQMLJS_DECLARE_AST_NODE(ContinueStatement)
ContinueStatement(const QStringRef &l = QStringRef()):
ContinueStatement(QStringView l = QStringView()):
label (l) { kind = K; }
void accept0(BaseVisitor *visitor) override;
@ -2000,7 +2000,7 @@ public:
{ return semicolonToken; }
// attributes
QStringRef label;
QStringView label;
SourceLocation continueToken;
SourceLocation identifierToken;
SourceLocation semicolonToken;
@ -2011,7 +2011,7 @@ class QML_PARSER_EXPORT BreakStatement: public Statement
public:
QQMLJS_DECLARE_AST_NODE(BreakStatement)
BreakStatement(const QStringRef &l):
BreakStatement(QStringView l):
label (l) { kind = K; }
void accept0(BaseVisitor *visitor) override;
@ -2023,7 +2023,7 @@ public:
{ return semicolonToken; }
// attributes
QStringRef label;
QStringView label;
SourceLocation breakToken;
SourceLocation identifierToken;
SourceLocation semicolonToken;
@ -2239,7 +2239,7 @@ class QML_PARSER_EXPORT LabelledStatement: public Statement
public:
QQMLJS_DECLARE_AST_NODE(LabelledStatement)
LabelledStatement(const QStringRef &l, Statement *stmt):
LabelledStatement(QStringView l, Statement *stmt):
label (l), statement (stmt)
{ kind = K; }
@ -2252,7 +2252,7 @@ public:
{ return statement->lastSourceLocation(); }
// attributes
QStringRef label;
QStringView label;
Statement *statement;
SourceLocation identifierToken;
SourceLocation colonToken;
@ -2372,7 +2372,7 @@ class QML_PARSER_EXPORT FunctionExpression: public ExpressionNode
public:
QQMLJS_DECLARE_AST_NODE(FunctionExpression)
FunctionExpression(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
FunctionExpression(QStringView n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
name (n), formals (f), body (b),
typeAnnotation(typeAnnotation)
{ kind = K; }
@ -2388,7 +2388,7 @@ public:
FunctionExpression *asFunctionDefinition() override;
// attributes
QStringRef name;
QStringView name;
bool isArrowFunction = false;
bool isGenerator = false;
FormalParameterList *formals;
@ -2407,7 +2407,7 @@ class QML_PARSER_EXPORT FunctionDeclaration: public FunctionExpression
public:
QQMLJS_DECLARE_AST_NODE(FunctionDeclaration)
FunctionDeclaration(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
FunctionDeclaration(QStringView n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
FunctionExpression(n, f, b, typeAnnotation)
{ kind = K; }
@ -2504,7 +2504,7 @@ class QML_PARSER_EXPORT ClassExpression : public ExpressionNode
public:
QQMLJS_DECLARE_AST_NODE(ClassExpression)
ClassExpression(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements)
ClassExpression(QStringView n, ExpressionNode *heritage, ClassElementList *elements)
: name(n), heritage(heritage), elements(elements)
{ kind = K; }
@ -2519,7 +2519,7 @@ public:
ClassExpression *asClassDefinition() override;
// attributes
QStringRef name;
QStringView name;
ExpressionNode *heritage;
ClassElementList *elements;
SourceLocation classToken;
@ -2533,7 +2533,7 @@ class QML_PARSER_EXPORT ClassDeclaration: public ClassExpression
public:
QQMLJS_DECLARE_AST_NODE(ClassDeclaration)
ClassDeclaration(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements)
ClassDeclaration(QStringView n, ExpressionNode *heritage, ClassElementList *elements)
: ClassExpression(n, heritage, elements)
{ kind = K; }
@ -2604,13 +2604,13 @@ class QML_PARSER_EXPORT ImportSpecifier: public Node
public:
QQMLJS_DECLARE_AST_NODE(ImportSpecifier)
ImportSpecifier(const QStringRef &importedBinding)
ImportSpecifier(QStringView importedBinding)
: importedBinding(importedBinding)
{
kind = K;
}
ImportSpecifier(const QStringRef &identifier, const QStringRef &importedBinding)
ImportSpecifier(QStringView identifier, QStringView importedBinding)
: identifier(identifier), importedBinding(importedBinding)
{
kind = K;
@ -2626,8 +2626,8 @@ public:
// attributes
SourceLocation identifierToken;
SourceLocation importedBindingToken;
QStringRef identifier;
QStringRef importedBinding;
QStringView identifier;
QStringView importedBinding;
};
class QML_PARSER_EXPORT ImportsList: public Node
@ -2711,7 +2711,7 @@ class QML_PARSER_EXPORT NameSpaceImport: public Node
public:
QQMLJS_DECLARE_AST_NODE(NameSpaceImport)
NameSpaceImport(const QStringRef &importedBinding)
NameSpaceImport(QStringView importedBinding)
: importedBinding(importedBinding)
{
kind = K;
@ -2727,7 +2727,7 @@ public:
// attributes
SourceLocation starToken;
SourceLocation importedBindingToken;
QStringRef importedBinding;
QStringView importedBinding;
};
class QML_PARSER_EXPORT ImportClause: public Node
@ -2735,7 +2735,7 @@ class QML_PARSER_EXPORT ImportClause: public Node
public:
QQMLJS_DECLARE_AST_NODE(ImportClause)
ImportClause(const QStringRef &importedDefaultBinding)
ImportClause(QStringView importedDefaultBinding)
: importedDefaultBinding(importedDefaultBinding)
{
kind = K;
@ -2753,14 +2753,14 @@ public:
kind = K;
}
ImportClause(const QStringRef &importedDefaultBinding, NameSpaceImport *nameSpaceImport)
ImportClause(QStringView importedDefaultBinding, NameSpaceImport *nameSpaceImport)
: importedDefaultBinding(importedDefaultBinding)
, nameSpaceImport(nameSpaceImport)
{
kind = K;
}
ImportClause(const QStringRef &importedDefaultBinding, NamedImports *namedImports)
ImportClause(QStringView importedDefaultBinding, NamedImports *namedImports)
: importedDefaultBinding(importedDefaultBinding)
, namedImports(namedImports)
{
@ -2776,7 +2776,7 @@ public:
// attributes
SourceLocation importedDefaultBindingToken;
QStringRef importedDefaultBinding;
QStringView importedDefaultBinding;
NameSpaceImport *nameSpaceImport = nullptr;
NamedImports *namedImports = nullptr;
};
@ -2786,7 +2786,7 @@ class QML_PARSER_EXPORT FromClause: public Node
public:
QQMLJS_DECLARE_AST_NODE(FromClause)
FromClause(const QStringRef &moduleSpecifier)
FromClause(QStringView moduleSpecifier)
: moduleSpecifier(moduleSpecifier)
{
kind = K;
@ -2803,7 +2803,7 @@ public:
// attributes
SourceLocation fromToken;
SourceLocation moduleSpecifierToken;
QStringRef moduleSpecifier;
QStringView moduleSpecifier;
};
class QML_PARSER_EXPORT ImportDeclaration: public Statement
@ -2817,7 +2817,7 @@ public:
kind = K;
}
ImportDeclaration(const QStringRef &moduleSpecifier)
ImportDeclaration(QStringView moduleSpecifier)
: moduleSpecifier(moduleSpecifier)
{
kind = K;
@ -2834,7 +2834,7 @@ public:
// attributes
SourceLocation importToken;
SourceLocation moduleSpecifierToken;
QStringRef moduleSpecifier;
QStringView moduleSpecifier;
ImportClause *importClause = nullptr;
FromClause *fromClause = nullptr;
};
@ -2844,13 +2844,13 @@ class QML_PARSER_EXPORT ExportSpecifier: public Node
public:
QQMLJS_DECLARE_AST_NODE(ExportSpecifier)
ExportSpecifier(const QStringRef &identifier)
ExportSpecifier(QStringView identifier)
: identifier(identifier), exportedIdentifier(identifier)
{
kind = K;
}
ExportSpecifier(const QStringRef &identifier, const QStringRef &exportedIdentifier)
ExportSpecifier(QStringView identifier, QStringView exportedIdentifier)
: identifier(identifier), exportedIdentifier(exportedIdentifier)
{
kind = K;
@ -2866,8 +2866,8 @@ public:
// attributes
SourceLocation identifierToken;
SourceLocation exportedIdentifierToken;
QStringRef identifier;
QStringRef exportedIdentifier;
QStringView identifier;
QStringView exportedIdentifier;
};
class QML_PARSER_EXPORT ExportsList: public Node
@ -3038,7 +3038,7 @@ class QML_PARSER_EXPORT UiImport: public Node
public:
QQMLJS_DECLARE_AST_NODE(UiImport)
UiImport(const QStringRef &fileName)
UiImport(QStringView fileName)
: fileName(fileName), importUri(nullptr)
{ kind = K; }
@ -3055,9 +3055,9 @@ public:
{ return semicolonToken; }
// attributes
QStringRef fileName;
QStringView fileName;
UiQualifiedId *importUri;
QStringRef importId;
QStringView importId;
SourceLocation importToken;
SourceLocation fileNameToken;
SourceLocation asToken;
@ -3120,7 +3120,7 @@ class QML_PARSER_EXPORT UiPragma: public Node
public:
QQMLJS_DECLARE_AST_NODE(UiPragma)
UiPragma(QStringRef name)
UiPragma(QStringView name)
: name(name)
{ kind = K; }
@ -3133,7 +3133,7 @@ public:
{ return semicolonToken; }
// attributes
QStringRef name;
QStringView name;
SourceLocation pragmaToken;
SourceLocation semicolonToken;
};
@ -3143,7 +3143,7 @@ class QML_PARSER_EXPORT UiRequired: public Node
public:
QQMLJS_DECLARE_AST_NODE(UiRequired)
UiRequired(QStringRef name)
UiRequired(QStringView name)
:name(name)
{ kind = K; }
@ -3155,7 +3155,7 @@ public:
SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
QStringRef name;
QStringView name;
SourceLocation requiredToken;
SourceLocation semicolonToken;
};
@ -3309,11 +3309,11 @@ class QML_PARSER_EXPORT UiParameterList: public Node
public:
QQMLJS_DECLARE_AST_NODE(UiParameterList)
UiParameterList(UiQualifiedId *t, const QStringRef &n):
UiParameterList(UiQualifiedId *t, QStringView n):
type (t), name (n), next (this)
{ kind = K; }
UiParameterList(UiParameterList *previous, UiQualifiedId *t, const QStringRef &n):
UiParameterList(UiParameterList *previous, UiQualifiedId *t, QStringView n):
type (t), name (n)
{
kind = K;
@ -3341,7 +3341,7 @@ public:
// attributes
UiQualifiedId *type;
QStringRef name;
QStringView name;
UiParameterList *next;
SourceLocation commaToken;
SourceLocation propertyTypeToken;
@ -3355,12 +3355,12 @@ public:
QQMLJS_DECLARE_AST_NODE(UiPublicMember)
UiPublicMember(UiQualifiedId *memberType,
const QStringRef &name)
QStringView name)
: type(Property), memberType(memberType), name(name), statement(nullptr), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr)
{ kind = K; }
UiPublicMember(UiQualifiedId *memberType,
const QStringRef &name,
QStringView name,
Statement *statement)
: type(Property), memberType(memberType), name(name), statement(statement), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr)
{ kind = K; }
@ -3391,9 +3391,9 @@ public:
// attributes
enum { Signal, Property } type;
QStringRef typeModifier;
QStringView typeModifier;
UiQualifiedId *memberType;
QStringRef name;
QStringView name;
Statement *statement; // initialized with a JS expression
UiObjectMember *binding; // initialized with a QML object or array.
bool isDefaultMember;
@ -3440,7 +3440,7 @@ class QML_PARSER_EXPORT UiInlineComponent: public UiObjectMember
public:
QQMLJS_DECLARE_AST_NODE(UiInlineComponent)
UiInlineComponent(const QStringRef& inlineComponentName, UiObjectDefinition* inlineComponent)
UiInlineComponent(QStringView inlineComponentName, UiObjectDefinition* inlineComponent)
: name(inlineComponentName), component(inlineComponent)
{ kind = K; }
@ -3453,7 +3453,7 @@ public:
void accept0(BaseVisitor *visitor) override;
// attributes
QStringRef name;
QStringView name;
UiObjectDefinition* component;
SourceLocation componentToken;
};
@ -3586,11 +3586,11 @@ class QML_PARSER_EXPORT UiEnumMemberList: public Node
{
QQMLJS_DECLARE_AST_NODE(UiEnumMemberList)
public:
UiEnumMemberList(const QStringRef &member, double v = 0.0)
UiEnumMemberList(QStringView member, double v = 0.0)
: next(this), member(member), value(v)
{ kind = K; }
UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member)
UiEnumMemberList(UiEnumMemberList *previous, QStringView member)
: member(member)
{
kind = K;
@ -3599,7 +3599,7 @@ public:
value = previous->value + 1;
}
UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member, double v)
UiEnumMemberList(UiEnumMemberList *previous, QStringView member, double v)
: member(member), value(v)
{
kind = K;
@ -3627,7 +3627,7 @@ public:
// attributes
UiEnumMemberList *next;
QStringRef member;
QStringView member;
double value;
SourceLocation memberToken;
SourceLocation valueToken;
@ -3638,7 +3638,7 @@ class QML_PARSER_EXPORT UiEnumDeclaration: public UiObjectMember
public:
QQMLJS_DECLARE_AST_NODE(UiEnumDeclaration)
UiEnumDeclaration(const QStringRef &name,
UiEnumDeclaration(QStringView name,
UiEnumMemberList *members)
: name(name)
, members(members)
@ -3655,7 +3655,7 @@ public:
// attributes
SourceLocation enumToken;
SourceLocation rbraceToken;
QStringRef name;
QStringView name;
UiEnumMemberList *members;
};

View File

@ -143,14 +143,13 @@ void Engine::setDirectives(Directives *directives)
MemoryPool *Engine::pool()
{ return &_pool; }
QStringRef Engine::newStringRef(const QString &text)
QStringView Engine::newStringRef(const QString &text)
{
const int pos = _extraCode.length();
_extraCode += text;
return _extraCode.midRef(pos, text.length());
_extraCode.append(text);
return QStringView{_extraCode.last()};
}
QStringRef Engine::newStringRef(const QChar *chars, int size)
QStringView Engine::newStringRef(const QChar *chars, int size)
{ return newStringRef(QString(chars, size)); }
} // end of namespace QQmlJS

View File

@ -98,7 +98,7 @@ class QML_PARSER_EXPORT Engine
Directives *_directives;
MemoryPool _pool;
QList<SourceLocation> _comments;
QString _extraCode;
QStringList _extraCode;
QString _code;
public:
@ -119,10 +119,10 @@ public:
MemoryPool *pool();
inline QStringRef midRef(int position, int size) { return _code.midRef(position, size); }
inline QStringView midRef(int position, int size) { return QStringView{_code}.mid(position, size); }
QStringRef newStringRef(const QString &s);
QStringRef newStringRef(const QChar *chars, int size);
QStringView newStringRef(const QString &s);
QStringView newStringRef(const QChar *chars, int size);
};
double integerFromString(const char *buf, int size, int radix);

View File

@ -132,8 +132,8 @@ void Lexer::setCode(const QString &code, int lineno, bool qmlMode)
_tokenText.clear();
_tokenText.reserve(1024);
_errorMessage.clear();
_tokenSpell = QStringRef();
_rawString = QStringRef();
_tokenSpell = QStringView();
_rawString = QStringView();
_codePtr = code.unicode();
_endPtr = _codePtr + code.length();
@ -256,8 +256,8 @@ int Lexer::lex()
const int previousTokenKind = _tokenKind;
again:
_tokenSpell = QStringRef();
_rawString = QStringRef();
_tokenSpell = QStringView();
_rawString = QStringView();
_tokenKind = scanToken();
_tokenLength = _codePtr - _tokenStartPtr - 1;

View File

@ -165,8 +165,8 @@ public:
int tokenStartLine() const { return _tokenLine; }
int tokenStartColumn() const { return _tokenColumn; }
inline QStringRef tokenSpell() const { return _tokenSpell; }
inline QStringRef rawString() const { return _rawString; }
inline QStringView tokenSpell() const { return _tokenSpell; }
inline QStringView rawString() const { return _rawString; }
double tokenValue() const { return _tokenValue; }
QString tokenText() const;
@ -219,8 +219,8 @@ private:
QString _code;
QString _tokenText;
QString _errorMessage;
QStringRef _tokenSpell;
QStringRef _rawString;
QStringView _tokenSpell;
QStringView _rawString;
const QChar *_codePtr;
const QChar *_endPtr;

View File

@ -100,7 +100,7 @@ class Q_QML_PRIVATE_EXPORT QHashedStringRef
public:
inline QHashedStringRef();
inline QHashedStringRef(const QString &);
inline QHashedStringRef(const QStringRef &);
inline QHashedStringRef(QStringView);
inline QHashedStringRef(const QChar *, int);
inline QHashedStringRef(const QChar *, int, quint32);
inline QHashedStringRef(const QHashedString &);
@ -242,7 +242,7 @@ QHashedStringRef::QHashedStringRef(const QString &str)
{
}
QHashedStringRef::QHashedStringRef(const QStringRef &str)
QHashedStringRef::QHashedStringRef(QStringView str)
: m_data(str.constData()), m_length(str.length()), m_hash(0)
{
}

View File

@ -253,7 +253,7 @@ template<typename T>
struct HashedForm {};
template<> struct HashedForm<QString> { typedef QHashedString Type; };
template<> struct HashedForm<QStringRef> { typedef QHashedStringRef Type; };
template<> struct HashedForm<QStringView> { typedef QHashedStringRef Type; };
template<> struct HashedForm<QHashedString> { typedef const QHashedString &Type; };
template<> struct HashedForm<QV4::String *> { typedef const QV4::String *Type; };
template<> struct HashedForm<const QV4::String *> { typedef const QV4::String *Type; };
@ -265,7 +265,7 @@ class QStringHashBase
{
public:
static HashedForm<QString>::Type hashedString(const QString &s) { return QHashedString(s);}
static HashedForm<QStringRef>::Type hashedString(const QStringRef &s) { return QHashedStringRef(s.constData(), s.size());}
static HashedForm<QStringView>::Type hashedString(QStringView s) { return QHashedStringRef(s.constData(), s.size());}
static HashedForm<QHashedString>::Type hashedString(const QHashedString &s) { return s; }
static HashedForm<QV4::String *>::Type hashedString(QV4::String *s) { return s; }
static HashedForm<const QV4::String *>::Type hashedString(const QV4::String *s) { return s; }

View File

@ -318,10 +318,10 @@ QDebug operator<<(QDebug debug, const QQmlError &error)
QByteArray data = f.readAll();
QTextStream stream(data, QIODevice::ReadOnly);
const QString code = stream.readAll();
const auto lines = code.splitRef(QLatin1Char('\n'));
const auto lines = QStringView{code}.split(QLatin1Char('\n'));
if (lines.count() >= error.line()) {
const QStringRef &line = lines.at(error.line() - 1);
const QStringView &line = lines.at(error.line() - 1);
debug << "\n " << line.toLocal8Bit().constData();
if(error.column() > 0) {

View File

@ -616,13 +616,13 @@ QString QQmlFile::urlToLocalFileOrQrc(const QString& url)
{
if (url.startsWith(QLatin1String("qrc://"), Qt::CaseInsensitive)) {
if (url.length() > 6)
return QLatin1Char(':') + url.midRef(6);
return QLatin1Char(':') + QStringView{url}.mid(6);
return QString();
}
if (url.startsWith(QLatin1String("qrc:"), Qt::CaseInsensitive)) {
if (url.length() > 4)
return QLatin1Char(':') + url.midRef(4);
return QLatin1Char(':') + QStringView{url}.mid(4);
return QString();
}

View File

@ -92,7 +92,7 @@ QString resolveLocalUrl(const QString &url, const QString &relative)
} else if (relative.at(0) == Slash || !url.contains(Slash)) {
return relative;
} else {
const QStringRef baseRef = url.leftRef(url.lastIndexOf(Slash) + 1);
const QStringView baseRef = QStringView{url}.left(url.lastIndexOf(Slash) + 1);
if (relative == QLatin1String("."))
return baseRef.toString();
@ -406,7 +406,7 @@ bool excludeBaseUrl(const QString &importUrl, const QString &fileName, const QSt
if (baseUrl.startsWith(importUrl))
{
if (fileName == baseUrl.midRef(importUrl.size()))
if (fileName == QStringView{baseUrl}.mid(importUrl.size()))
return false;
}
@ -1000,17 +1000,17 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS
QString u1 = import->url;
QString u2 = import2->url;
if (base) {
QStringRef b(base);
QStringView b(*base);
int dot = b.lastIndexOf(Dot);
if (dot >= 0) {
b = b.left(dot+1);
QStringRef l = b.left(dot);
QStringView l = b.left(dot);
if (u1.startsWith(b))
u1 = u1.mid(b.count());
u1 = u1.mid(b.size());
else if (u1 == l)
u1 = QQmlImportDatabase::tr("local directory");
if (u2.startsWith(b))
u2 = u2.mid(b.count());
u2 = u2.mid(b.size());
else if (u2 == l)
u2 = QQmlImportDatabase::tr("local directory");
}
@ -1400,7 +1400,7 @@ QQmlImports::LocalQmldirResult QQmlImportsPrivate::locateLocalQmldir(
QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath);
if (!absoluteFilePath.isEmpty()) {
QString url;
const QStringRef absolutePath = absoluteFilePath.leftRef(absoluteFilePath.lastIndexOf(Slash) + 1);
const QStringView absolutePath = QStringView{absoluteFilePath}.left(absoluteFilePath.lastIndexOf(Slash) + 1);
if (absolutePath.at(0) == Colon)
url = QLatin1String("qrc") + absolutePath;
else

View File

@ -91,7 +91,7 @@ public:
inline QQmlInfo &operator<<(double t) { QDebug::operator<<(t); return *this; }
inline QQmlInfo &operator<<(const char* t) { QDebug::operator<<(t); return *this; }
inline QQmlInfo &operator<<(const QString & t) { QDebug::operator<<(t.toLocal8Bit().constData()); return *this; }
inline QQmlInfo &operator<<(const QStringRef & t) { return operator<<(t.toString()); }
inline QQmlInfo &operator<<(QStringView t) { return operator<<(t.toString()); }
inline QQmlInfo &operator<<(const QLatin1String &t) { QDebug::operator<<(t.latin1()); return *this; }
inline QQmlInfo &operator<<(const QByteArray & t) { QDebug::operator<<(t); return *this; }
inline QQmlInfo &operator<<(const void * t) { QDebug::operator<<(t); return *this; }

View File

@ -1481,7 +1481,7 @@ QString QQmlMetaType::prettyTypeName(const QObject *object)
marker = typeName.indexOf(QLatin1String("_QML_"));
if (marker != -1) {
typeName = typeName.leftRef(marker) + QLatin1Char('*');
typeName = QStringView{typeName}.left(marker) + QLatin1Char('*');
type = QQmlMetaType::qmlType(QMetaType::type(typeName.toLatin1()));
if (type.isValid()) {
QString qmlTypeName = type.qmlTypeName();

View File

@ -262,16 +262,16 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
QQmlRefPointer<QQmlTypeNameCache> typeNameCache = context ? context->imports() : nullptr;
QObject *currentObject = obj;
QVector<QStringRef> path;
QStringRef terminal(&name);
QList<QStringView> path;
QStringView terminal(name);
if (name.contains(QLatin1Char('.'))) {
path = name.splitRef(QLatin1Char('.'));
path = QStringView{name}.split(QLatin1Char('.'));
if (path.isEmpty()) return;
// Everything up to the last property must be an "object type" property
for (int ii = 0; ii < path.count() - 1; ++ii) {
const QStringRef &pathName = path.at(ii);
const QStringView &pathName = path.at(ii);
// Types must begin with an uppercase letter (see checkRegistration()
// in qqmlmetatype.cpp for the enforcement of this).
@ -355,7 +355,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
terminal = path.last();
}
if (terminal.count() >= 3 && terminal.at(0) == u'o' && terminal.at(1) == u'n'
if (terminal.size() >= 3 && terminal.at(0) == u'o' && terminal.at(1) == u'n'
&& (terminal.at(2).isUpper() || terminal.at(2) == u'_')) {
QString signalName = terminal.mid(2).toString();
@ -384,7 +384,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
// Try property
if (signalName.endsWith(QLatin1String("Changed"))) {
const QStringRef propName = signalName.midRef(0, signalName.length() - 7);
const QStringView propName = QStringView{signalName}.mid(0, signalName.length() - 7);
QQmlPropertyData *d = ddata->propertyCache->property(propName, currentObject, context);
while (d && d->isFunction())
d = ddata->propertyCache->overrideData(d);

View File

@ -551,7 +551,7 @@ void QQmlPropertyCache::append(const QMetaObject *metaObject,
setNamedProperty(methodName, ii, data, (old != nullptr));
if (data->isSignal()) {
QHashedString on(QLatin1String("on") % methodName.at(0).toUpper() % methodName.midRef(1));
QHashedString on(QLatin1String("on") % methodName.at(0).toUpper() % QStringView{methodName}.mid(1));
setNamedProperty(on, ii, sigdata, (old != nullptr));
++signalHandlerIndex;
}
@ -991,7 +991,7 @@ static inline const char *qQmlPropertyCacheToString(QLatin1String string)
return string.data();
}
static inline QByteArray qQmlPropertyCacheToString(const QStringRef &string)
static inline QByteArray qQmlPropertyCacheToString(QStringView string)
{
return string.toUtf8();
}
@ -1043,10 +1043,10 @@ QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QV4::String *
}
QQmlPropertyData *
QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QStringRef &name,
QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, QStringView name,
const QQmlRefPointer<QQmlContextData> &context, QQmlPropertyData *local)
{
return qQmlPropertyCacheProperty<const QStringRef &>(engine, obj, name, context, local);
return qQmlPropertyCacheProperty<const QStringView &>(engine, obj, name, context, local);
}
QQmlPropertyData *

View File

@ -185,7 +185,7 @@ public:
inline QQmlPropertyData *overrideData(QQmlPropertyData *) const;
inline bool isAllowedInRevision(QQmlPropertyData *) const;
static QQmlPropertyData *property(QJSEngine *, QObject *, const QStringRef &,
static QQmlPropertyData *property(QJSEngine *, QObject *, QStringView,
const QQmlRefPointer<QQmlContextData> &, QQmlPropertyData *);
static QQmlPropertyData *property(QJSEngine *, QObject *, const QLatin1String &,
const QQmlRefPointer<QQmlContextData> &, QQmlPropertyData *);
@ -196,7 +196,7 @@ public:
const QQmlRefPointer<QQmlContextData> &context,
QQmlPropertyData *local)
{
return property(engine, obj, QStringRef(&name), context, local);
return property(engine, obj, QStringView(name), context, local);
}
//see QMetaObjectPrivate::originalClone

View File

@ -82,7 +82,7 @@ QByteArray QQmlPropertyCacheCreatorBase::createClassNameTypeByUrl(const QUrl &ur
if (lastSlash <= -1)
return QByteArray();
// ### this might not be correct for .ui.qml files
const QStringRef nameBase = path.midRef(lastSlash + 1, path.length() - lastSlash - 5);
const QStringView nameBase = QStringView{path}.mid(lastSlash + 1, path.length() - lastSlash - 5);
// Not a reusable type if it doesn't start with a upper case letter.
if (nameBase.isEmpty() || !nameBase.at(0).isUpper())
return QByteArray();

View File

@ -143,8 +143,8 @@ QPointF QQmlStringConverters::pointFFromString(const QString &s, bool *ok)
bool xGood, yGood;
int index = s.indexOf(QLatin1Char(','));
qreal xCoord = s.leftRef(index).toDouble(&xGood);
qreal yCoord = s.midRef(index+1).toDouble(&yGood);
qreal xCoord = QStringView{s}.left(index).toDouble(&xGood);
qreal yCoord = QStringView{s}.mid(index+1).toDouble(&yGood);
if (!xGood || !yGood) {
if (ok)
*ok = false;
@ -167,8 +167,8 @@ QSizeF QQmlStringConverters::sizeFFromString(const QString &s, bool *ok)
bool wGood, hGood;
int index = s.indexOf(QLatin1Char('x'));
qreal width = s.leftRef(index).toDouble(&wGood);
qreal height = s.midRef(index+1).toDouble(&hGood);
qreal width = QStringView{s}.left(index).toDouble(&wGood);
qreal height = QStringView{s}.mid(index+1).toDouble(&hGood);
if (!wGood || !hGood) {
if (ok)
*ok = false;
@ -191,12 +191,12 @@ QRectF QQmlStringConverters::rectFFromString(const QString &s, bool *ok)
bool xGood, yGood, wGood, hGood;
int index = s.indexOf(QLatin1Char(','));
qreal x = s.leftRef(index).toDouble(&xGood);
qreal x = QStringView{s}.left(index).toDouble(&xGood);
int index2 = s.indexOf(QLatin1Char(','), index+1);
qreal y = s.midRef(index+1, index2-index-1).toDouble(&yGood);
qreal y = QStringView{s}.mid(index+1, index2-index-1).toDouble(&yGood);
index = s.indexOf(QLatin1Char('x'), index2+1);
qreal width = s.midRef(index2+1, index-index2-1).toDouble(&wGood);
qreal height = s.midRef(index+1).toDouble(&hGood);
qreal width = QStringView{s}.mid(index2+1, index-index2-1).toDouble(&wGood);
qreal height = QStringView{s}.mid(index+1).toDouble(&hGood);
if (!xGood || !yGood || !wGood || !hGood) {
if (ok)
*ok = false;

View File

@ -846,7 +846,7 @@ int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, const QByteArray &scope
return -1;
}
int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, const QStringRef &scopedEnumName, const QStringRef &name, bool *ok) const
int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, QStringView scopedEnumName, QStringView name, bool *ok) const
{
Q_ASSERT(ok);
if (d) {

View File

@ -169,7 +169,7 @@ public:
int scopedEnumValue(QQmlEnginePrivate *engine, int index, const QV4::String *, bool *ok) const;
int scopedEnumValue(QQmlEnginePrivate *engine, int index, const QString &, bool *ok) const;
int scopedEnumValue(QQmlEnginePrivate *engine, const QByteArray &, const QByteArray &, bool *ok) const;
int scopedEnumValue(QQmlEnginePrivate *engine, const QStringRef &, const QStringRef &, bool *ok) const;
int scopedEnumValue(QQmlEnginePrivate *engine, QStringView, QStringView, bool *ok) const;
int inlineComponentObjectId() const;
void setInlineComponentObjectId(int id) const; // TODO: const setters are BAD

View File

@ -249,7 +249,7 @@ QQmlJS::MemoryPool *QQmlTypeCompiler::memoryPool()
return document->jsParserEngine.pool();
}
QStringRef QQmlTypeCompiler::newStringRef(const QString &string)
QStringView QQmlTypeCompiler::newStringRef(const QString &string)
{
return document->jsParserEngine.newStringRef(string);
}
@ -468,7 +468,7 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio
QQmlJS::AST::FormalParameterList *paramList = nullptr;
for (const QString &param : qAsConst(parameters)) {
QStringRef paramNameRef = compiler->newStringRef(param);
QStringView paramNameRef = compiler->newStringRef(param);
QQmlJS::AST::PatternElement *b = new (pool) QQmlJS::AST::PatternElement(paramNameRef, nullptr);
paramList = new (pool) QQmlJS::AST::FormalParameterList(paramList, b);
@ -551,7 +551,7 @@ bool QQmlEnumTypeResolver::resolveEnumBindings()
return true;
}
bool QQmlEnumTypeResolver::assignEnumToBinding(QmlIR::Binding *binding, const QStringRef &, int enumValue, bool)
bool QQmlEnumTypeResolver::assignEnumToBinding(QmlIR::Binding *binding, QStringView, int enumValue, bool)
{
binding->type = QV4::CompiledData::Binding::Type_Number;
binding->value.constantValueIndex = compiler->registerConstant(QV4::Encode((double)enumValue));
@ -592,9 +592,9 @@ bool QQmlEnumTypeResolver::tryQualifiedEnumAssignment(const QmlIR::Object *obj,
QHashedStringRef typeName(string.constData(), dot);
const bool isQtObject = (typeName == QLatin1String("Qt"));
const QStringRef scopedEnumName = (dot2 != -1 ? string.midRef(dot + 1, dot2 - dot - 1) : QStringRef());
const QStringView scopedEnumName = (dot2 != -1 ? QStringView{string}.mid(dot + 1, dot2 - dot - 1) : QStringView());
// ### consider supporting scoped enums in Qt namespace
const QStringRef enumValue = string.midRef(!isQtObject && dot2 != -1 ? dot2 + 1 : dot + 1);
const QStringView enumValue = QStringView{string}.mid(!isQtObject && dot2 != -1 ? dot2 + 1 : dot + 1);
if (isIntProp) { // ### C++11 allows enums to be other integral types. Should we support other integral types here?
// Allow enum assignment to ints.
@ -652,7 +652,7 @@ bool QQmlEnumTypeResolver::tryQualifiedEnumAssignment(const QmlIR::Object *obj,
return assignEnumToBinding(binding, enumValue, value, isQtObject);
}
int QQmlEnumTypeResolver::evaluateEnum(const QString &scope, const QStringRef &enumName, const QStringRef &enumValue, bool *ok) const
int QQmlEnumTypeResolver::evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const
{
Q_ASSERT_X(ok, "QQmlEnumTypeResolver::evaluateEnum", "ok must not be a null pointer");
*ok = false;
@ -1104,15 +1104,15 @@ QQmlComponentAndAliasResolver::resolveAliasesInObject(int objectIndex,
const QString aliasPropertyValue = stringAt(alias->propertyNameIndex);
QStringRef property;
QStringRef subProperty;
QStringView property;
QStringView subProperty;
const int propertySeparator = aliasPropertyValue.indexOf(QLatin1Char('.'));
if (propertySeparator != -1) {
property = aliasPropertyValue.leftRef(propertySeparator);
subProperty = aliasPropertyValue.midRef(propertySeparator + 1);
property = QStringView{aliasPropertyValue}.left(propertySeparator);
subProperty = QStringView{aliasPropertyValue}.mid(propertySeparator + 1);
} else
property = QStringRef(&aliasPropertyValue, 0, aliasPropertyValue.length());
property = QStringView(aliasPropertyValue);
QQmlPropertyIndex propIdx;

View File

@ -118,7 +118,7 @@ public:
void setComponentRoots(const QVector<quint32> &roots) { m_componentRoots = roots; }
const QVector<quint32> &componentRoots() const { return m_componentRoots; }
QQmlJS::MemoryPool *memoryPool();
QStringRef newStringRef(const QString &string);
QStringView newStringRef(const QString &string);
const QV4::Compiler::StringTableGenerator *stringPool() const;
const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; }
@ -207,15 +207,15 @@ public:
bool resolveEnumBindings();
private:
bool assignEnumToBinding(QmlIR::Binding *binding, const QStringRef &enumName, int enumValue, bool isQtObject);
bool assignEnumToBinding(QmlIR::Binding *binding, QStringView enumName, int enumValue, bool isQtObject);
bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
{
return assignEnumToBinding(binding, QStringRef(&enumName), enumValue, isQtObject);
return assignEnumToBinding(binding, QStringView(enumName), enumValue, isQtObject);
}
bool tryQualifiedEnumAssignment(const QmlIR::Object *obj, const QQmlPropertyCache *propertyCache,
const QQmlPropertyData *prop,
QmlIR::Binding *binding);
int evaluateEnum(const QString &scope, const QStringRef &enumName, const QStringRef &enumValue, bool *ok) const;
int evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const;
const QVector<QmlIR::Object*> &qmlObjects;

View File

@ -358,7 +358,7 @@ void QQmlTypeData::done()
error.setUrl(url());
error.setLine(qmlConvertSourceCoordinate<quint32, int>(type.location.line));
error.setColumn(qmlConvertSourceCoordinate<quint32, int>(type.location.column));
error.setDescription(QQmlTypeLoader::tr("Type %1 has no inline component type called %2").arg(typeName.leftRef(lastDot), type.type.pendingResolutionName()));
error.setDescription(QQmlTypeLoader::tr("Type %1 has no inline component type called %2").arg(QStringView{typeName}.left(lastDot), type.type.pendingResolutionName()));
errors.prepend(error);
setError(errors);
return;
@ -505,7 +505,7 @@ void QQmlTypeData::done()
// associate inline components to root component
{
auto typeName = finalUrlString().splitRef(u'/').last().split(u'.').first().toString();
auto typeName = QStringView{finalUrlString()}.split(u'/').last().split(u'.').first().toString();
// typeName can be empty if a QQmlComponent was constructed with an empty QUrl parameter
if (!typeName.isEmpty() && typeName.at(0).isUpper() && !m_inlineComponentData.isEmpty()) {
QHashedStringRef const hashedStringRef { typeName };
@ -529,7 +529,7 @@ void QQmlTypeData::done()
for (int scriptIndex = 0; scriptIndex < m_scripts.count(); ++scriptIndex) {
const QQmlTypeData::ScriptReference &script = m_scripts.at(scriptIndex);
QStringRef qualifier(&script.qualifier);
QStringView qualifier(script.qualifier);
QString enclosingNamespace;
const int lastDotIndex = qualifier.lastIndexOf(QLatin1Char('.'));

View File

@ -728,7 +728,7 @@ ReturnedValue Text::method_isElementContentWhitespace(const FunctionObject *b, c
if (!r)
RETURN_UNDEFINED();
return Encode(QStringRef(&r->d()->d->data).trimmed().isEmpty());
return Encode(QStringView(r->d()->d->data).trimmed().isEmpty());
}
ReturnedValue Text::method_wholeText(const FunctionObject *b, const Value *thisObject, const Value *, int)

View File

@ -43,7 +43,7 @@
QT_BEGIN_NAMESPACE
static int parseInt(const QStringRef &str, bool *ok)
static int parseInt(QStringView str, bool *ok)
{
int pos = 0;
int number = 0;
@ -65,9 +65,9 @@ static QTypeRevision parseVersion(const QString &str)
const int dotIndex = str.indexOf(QLatin1Char('.'));
if (dotIndex != -1 && str.indexOf(QLatin1Char('.'), dotIndex + 1) == -1) {
bool ok = false;
const int major = parseInt(QStringRef(&str, 0, dotIndex), &ok);
const int major = parseInt(QStringView(str).left(dotIndex), &ok);
if (!ok) return QTypeRevision();
const int minor = parseInt(QStringRef(&str, dotIndex + 1, str.length() - dotIndex - 1), &ok);
const int minor = parseInt(QStringView(str).mid(dotIndex + 1, str.length() - dotIndex - 1), &ok);
return ok ? QTypeRevision::fromVersion(major, minor) : QTypeRevision();
}
return QTypeRevision();

View File

@ -54,13 +54,13 @@ enum ImportVersion { FullyVersioned, PartiallyVersioned, Unversioned };
- base/QtQml.2/Models
- base/QtQml/Models
*/
QStringList qQmlResolveImportPaths(const QString &uri, const QStringList &basePaths,
QStringList qQmlResolveImportPaths(QStringView uri, const QStringList &basePaths,
QTypeRevision version)
{
static const QLatin1Char Slash('/');
static const QLatin1Char Backslash('\\');
const QVector<QStringRef> parts = uri.splitRef(QLatin1Char('.'), Qt::SkipEmptyParts);
const QVector<QStringView> parts = uri.split(u'.', Qt::SkipEmptyParts);
QStringList importPaths;
// fully & partially versioned parts + 1 unversioned for each base path
@ -81,7 +81,7 @@ QStringList qQmlResolveImportPaths(const QString &uri, const QStringList &basePa
return QString();
};
auto joinStringRefs = [](const QVector<QStringRef> &refs, const QChar &sep) {
auto joinStringRefs = [](const QVector<QStringView> &refs, const QChar &sep) {
QString str;
for (auto it = refs.cbegin(); it != refs.cend(); ++it) {
if (it != refs.cbegin())

View File

@ -57,7 +57,7 @@
QT_BEGIN_NAMESPACE
QStringList qQmlResolveImportPaths(const QString &uri, const QStringList &basePaths,
QStringList qQmlResolveImportPaths(QStringView uri, const QStringList &basePaths,
QTypeRevision version);
QT_END_NAMESPACE

View File

@ -1365,7 +1365,7 @@ QVariant QQmlDelegateModelPrivate::variantValue(QQmlListCompositor::Group group,
return QVariant();
const int from = dot + 1;
dot = name.indexOf(QLatin1Char('.'), from);
value = obj->property(name.midRef(from, dot - from).toUtf8());
value = obj->property(QStringView{name}.mid(from, dot - from).toUtf8());
}
return value;
}

View File

@ -576,7 +576,7 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch
QTestRootObject::instance()->init();
QString path = fi.absoluteFilePath();
if (path.startsWith(QLatin1String(":/")))
view.setSource(QUrl(QLatin1String("qrc:") + path.midRef(1)));
view.setSource(QUrl(QLatin1String("qrc:") + QStringView{path}.mid(1)));
else
view.setSource(QUrl::fromLocalFile(path));

View File

@ -1133,7 +1133,7 @@ static const char* mimeToType(const QString &mime)
const QLatin1String imagePrefix("image/");
if (!mime.startsWith(imagePrefix))
return nullptr;
const QStringRef mimeExt = mime.midRef(imagePrefix.size());
const QStringView mimeExt = QStringView{mime}.mid(imagePrefix.size());
if (mimeExt == QLatin1String("png"))
return "png";
else if (mimeExt == QLatin1String("bmp"))

View File

@ -205,7 +205,7 @@ Q_QUICK_PRIVATE_EXPORT QColor qt_color_from_string(const QV4::Value &name)
return QColor();
}
static int qParseFontSizeFromToken(const QStringRef &fontSizeToken, bool &ok)
static int qParseFontSizeFromToken(QStringView fontSizeToken, bool &ok)
{
ok = false;
float size = fontSizeToken.trimmed().toFloat(&ok);
@ -221,11 +221,11 @@ static int qParseFontSizeFromToken(const QStringRef &fontSizeToken, bool &ok)
\c true if successful. If the font size is invalid, \c false is returned
and a warning is printed.
*/
static bool qSetFontSizeFromToken(QFont &font, const QStringRef &fontSizeToken)
static bool qSetFontSizeFromToken(QFont &font, QStringView fontSizeToken)
{
const QStringRef trimmedToken = fontSizeToken.trimmed();
const QStringRef unitStr = trimmedToken.right(2);
const QStringRef value = trimmedToken.left(trimmedToken.size() - 2);
const QStringView trimmedToken = fontSizeToken.trimmed();
const QStringView unitStr = trimmedToken.right(2);
const QStringView value = trimmedToken.left(trimmedToken.size() - 2);
bool ok = false;
int size = 0;
if (unitStr == QLatin1String("px")) {
@ -251,7 +251,7 @@ static bool qSetFontSizeFromToken(QFont &font, const QStringRef &fontSizeToken)
each family is separated by spaces. Families with spaces in their name
must be quoted.
*/
static QStringList qExtractFontFamiliesFromString(const QStringRef &fontFamiliesString)
static QStringList qExtractFontFamiliesFromString(QStringView fontFamiliesString)
{
QStringList extractedFamilies;
int quoteIndex = -1;
@ -395,16 +395,16 @@ static QFont qt_font_from_string(const QString& fontString, const QFont &current
fontSizeEnd += 3;
QFont newFont;
if (!qSetFontSizeFromToken(newFont, fontString.midRef(fontSizeStart, fontSizeEnd - fontSizeStart)))
if (!qSetFontSizeFromToken(newFont, QStringView{fontString}.mid(fontSizeStart, fontSizeEnd - fontSizeStart)))
return currentFont;
// We don't want to parse the size twice, so remove it now.
QString remainingFontString = fontString;
remainingFontString.remove(fontSizeStart, fontSizeEnd - fontSizeStart);
QStringRef remainingFontStringRef(&remainingFontString);
QStringView remainingFontStringRef(remainingFontString);
// Next, we have to take any font families out, as QString::split() will ruin quoted family names.
const QStringRef fontFamiliesString = remainingFontStringRef.mid(fontSizeStart);
const QStringView fontFamiliesString = remainingFontStringRef.mid(fontSizeStart);
remainingFontStringRef.truncate(fontSizeStart);
QStringList fontFamilies = qExtractFontFamiliesFromString(fontFamiliesString);
if (fontFamilies.isEmpty()) {
@ -414,7 +414,7 @@ static QFont qt_font_from_string(const QString& fontString, const QFont &current
return currentFont;
// Now that we've removed the messy parts, we can split the font string on spaces.
const QStringRef trimmedTokensStr = remainingFontStringRef.trimmed();
const QStringView trimmedTokensStr = remainingFontStringRef.trimmed();
if (trimmedTokensStr.isEmpty()) {
// No optional properties.
return newFont;
@ -423,7 +423,7 @@ static QFont qt_font_from_string(const QString& fontString, const QFont &current
int usedTokens = NoTokens;
// Optional properties can be in any order, but font-size and font-family must be last.
for (const QStringRef &token : tokens) {
for (const QStringView &token : tokens) {
if (token.compare(QLatin1String("normal")) == 0) {
if (!(usedTokens & FontStyle) || !(usedTokens & FontVariant) || !(usedTokens & FontWeight)) {
// Could be font-style, font-variant or font-weight.

View File

@ -1990,7 +1990,7 @@ void QQuickPathView::refill()
if (lcItemViewDelegateLifecycle().isDebugEnabled()) {
QQuickText *text = qmlobject_cast<QQuickText*>(item);
if (text)
qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ": QQuickText" << text->objectName() << text->text().leftRef(40);
qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ": QQuickText" << text->objectName() << QStringView{text->text()}.left(40);
else
qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ":" << item;
}

View File

@ -140,8 +140,8 @@ QQuickGridScaledImage::QQuickGridScaledImage(QIODevice *data)
if (colonId <= 0)
return;
const QStringRef property = line.leftRef(colonId).trimmed();
QStringRef value = line.midRef(colonId + 1).trimmed();
const QStringView property = QStringView{line}.left(colonId).trimmed();
QStringView value = QStringView{line}.mid(colonId + 1).trimmed();
if (property == QLatin1String("border.left")) {
l = value.toInt();
@ -169,9 +169,9 @@ QQuickGridScaledImage::QQuickGridScaledImage(QIODevice *data)
_pix = imgFile;
}
QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(const QStringRef &s)
QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(QStringView s)
{
QStringRef string = s;
QStringView string = s;
if (string.startsWith(QLatin1Char('"')) && string.endsWith(QLatin1Char('"')))
string = string.mid(1, string.size() - 2); // remove leading/trailing quotes.

View File

@ -122,7 +122,7 @@ public:
QString pixmapUrl() const;
private:
static QQuickBorderImage::TileMode stringToRule(const QStringRef &);
static QQuickBorderImage::TileMode stringToRule(QStringView);
private:
int _l;

View File

@ -1461,7 +1461,7 @@ QVariant QQuickTextControl::inputMethodQuery(Qt::InputMethodQuery property, cons
tmpCursor.movePosition(QTextCursor::NextBlock);
--numBlocks;
}
result += block.text().midRef(0,localPos);
result += QStringView{block.text()}.mid(0,localPos);
return QVariant(result);
}
default:

View File

@ -1999,7 +1999,7 @@ QVariant QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery property, const
return QVariant(d->m_text.mid(d->m_cursor));
case Qt::ImTextBeforeCursor:
if (argument.isValid())
return QVariant(d->m_text.leftRef(d->m_cursor).right(argument.toInt()).toString());
return QVariant(QStringView{d->m_text}.left(d->m_cursor).right(argument.toInt()).toString());
return QVariant(d->m_text.left(d->m_cursor));
default:
return QQuickItem::inputMethodQuery(property);
@ -2041,7 +2041,7 @@ bool QQuickTextInput::isRightToLeft(int start, int end)
qmlWarning(this) << "isRightToLeft(start, end) called with the end property being smaller than the start.";
return false;
} else {
return text().midRef(start, end - start).isRightToLeft();
return QStringView{text()}.mid(start, end - start).isRightToLeft();
}
}
@ -3728,7 +3728,7 @@ void QQuickTextInputPrivate::internalInsert(const QString &s)
} else {
int remaining = m_maxLength - m_text.length();
if (remaining != 0) {
const QStringRef remainingStr = s.leftRef(remaining);
const QStringView remainingStr = QStringView{s}.left(remaining);
m_text.insert(m_cursor, remainingStr);
for (auto e : remainingStr)
addCommand(Command(Insert, m_cursor++, e, -1, -1));
@ -4084,14 +4084,14 @@ QString QQuickTextInputPrivate::maskString(uint pos, const QString &str, bool cl
int n = findInMask(i, true, true, str[strIndex]);
if (n != -1) {
if (str.length() != 1 || i == 0 || (i > 0 && (!m_maskData[i-1].separator || m_maskData[i-1].maskChar != str[strIndex]))) {
s += fill.midRef(i, n-i+1);
s += QStringView{fill}.mid(i, n-i+1);
i = n + 1; // update i to find + 1
}
} else {
// search for valid m_blank if not
n = findInMask(i, true, false, str[strIndex]);
if (n != -1) {
s += fill.midRef(i, n-i);
s += QStringView{fill}.mid(i, n-i);
switch (m_maskData[n].caseMode) {
case MaskInputData::Upper:
s += str[strIndex].toUpper();

View File

@ -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 << "...";
}

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -178,7 +178,7 @@ void tst_qqmlinfo::types()
//### should this be quoted?
QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: World");
QString str("Hello World");
QStringRef ref(&str, 6, 5);
auto ref = QStringView(str).mid(6, 5);
qmlInfo(nullptr) << ref;
//### should this be quoted?
@ -189,7 +189,7 @@ void tst_qqmlinfo::types()
void tst_qqmlinfo::chaining()
{
QString str("Hello World");
QStringRef ref(&str, 6, 5);
auto ref = QStringView(str).mid(6, 5);
QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' World \"Qt\" true Quick QUrl(\"http://www.qt-project.org\") ");
qmlInfo(nullptr) << false << ' '
<< 1.1 << ' '

View File

@ -342,7 +342,7 @@ void tst_qqmlparser::stringLiteral()
QVERIFY(expression);
auto *literal = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(expression);
QVERIFY(literal);
QCOMPARE(literal->value, "hello string");
QCOMPARE(literal->value, u"hello string");
QCOMPARE(literal->firstSourceLocation().begin(), 0u);
QCOMPARE(literal->lastSourceLocation().end(), quint32(code.size()));
@ -361,7 +361,7 @@ void tst_qqmlparser::stringLiteral()
literal = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(binaryExpression->left);
QVERIFY(literal);
QCOMPARE(literal->value, "hello\n\tstring");
QCOMPARE(literal->value, u"hello\n\tstring");
QCOMPARE(literal->firstSourceLocation().begin(), 0u);
QCOMPARE(literal->firstSourceLocation().startLine, 1u);
QCOMPARE(literal->lastSourceLocation().end(), quint32(leftCode.size()));
@ -369,7 +369,7 @@ void tst_qqmlparser::stringLiteral()
QVERIFY(binaryExpression->right);
literal = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(binaryExpression->right);
QVERIFY(literal);
QCOMPARE(literal->value, "\nbye");
QCOMPARE(literal->value, u"\nbye");
quint32 offset = quint32(leftCode.size() + plusCode.size());
QCOMPARE(literal->firstSourceLocation().begin(), offset);
QCOMPARE(literal->firstSourceLocation().startLine, 1u);
@ -387,14 +387,14 @@ void tst_qqmlparser::stringLiteral()
literal = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(binaryExpression->left);
QVERIFY(literal);
QCOMPARE(literal->value, "\nhello\nbye");
QCOMPARE(literal->value, u"\nhello\nbye");
QCOMPARE(literal->firstSourceLocation().begin(), 0u);
QCOMPARE(literal->firstSourceLocation().startLine, 1u);
QCOMPARE(literal->lastSourceLocation().end(), leftCode.size());
literal = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(binaryExpression->right);
QVERIFY(literal);
QCOMPARE(literal->value, "\nbye");
QCOMPARE(literal->value, u"\nbye");
offset = quint32(leftCode.size() + plusCode.size());
QCOMPARE(literal->firstSourceLocation().begin(), offset);
QCOMPARE(literal->lastSourceLocation().startLine, 3u);
@ -479,7 +479,7 @@ void tst_qqmlparser::noSubstitutionTemplateLiteral()
auto *literal = QQmlJS::AST::cast<QQmlJS::AST::TemplateLiteral *>(expression);
QVERIFY(literal);
QCOMPARE(literal->value, "hello template");
QCOMPARE(literal->value, u"hello template");
QCOMPARE(literal->firstSourceLocation().begin(), 0u);
QCOMPARE(literal->lastSourceLocation().end(), quint32(code.size()));
}
@ -696,7 +696,7 @@ void tst_qqmlparser::annotations_data()
for (const QString &file: qAsConst(files)) {
auto fileNameStart = file.lastIndexOf(QDir::separator());
QStringRef fileName(&file, fileNameStart, file.length()-fileNameStart);
auto fileName = QStringView(file).mid(fileNameStart, file.length()-fileNameStart);
auto ref=std::find_if(refFiles.constBegin(),refFiles.constEnd(), [fileName](const QString &s){ return s.endsWith(fileName); });
if (ref != refFiles.constEnd())
QTest::newRow(qPrintable(file)) << file << *ref;

View File

@ -212,7 +212,7 @@ QString AstDumper::qs(const char *s) {
return qs(QLatin1String(s));
}
QString AstDumper::qs(const QStringRef &s) {
QString AstDumper::qs(QStringView s) {
return qs(s.toString());
}

View File

@ -89,7 +89,7 @@ public:
QString qs(const QString &s);
QString qs(const char *s);
QString qs(const QStringRef &s);
QString qs(QStringView s);
QString loc(const SourceLocation &s);

View File

@ -61,7 +61,7 @@ int filterResourceFile(const QString &input, const QString &output)
while (!reader.atEnd()) {
switch (reader.readNext()) {
case QXmlStreamReader::StartDocument: {
QStringRef version = reader.documentVersion();
QStringView version = reader.documentVersion();
if (!version.isEmpty())
writer.writeStartDocument(version.toString());
else

View File

@ -675,12 +675,12 @@ void SplineEditor::setEasingCurve(const QString &code)
if (m_block)
return;
if (code.startsWith(QLatin1Char('[')) && code.endsWith(QLatin1Char(']'))) {
const QStringRef cleanCode(&code, 1, code.size() - 2);
const auto cleanCode = QStringView(code).mid(1, code.size() - 2);
const auto stringList = cleanCode.split(QLatin1Char(','), Qt::SkipEmptyParts);
if (stringList.count() >= 6 && (stringList.count() % 6 == 0)) {
QVector<qreal> realList;
realList.reserve(stringList.count());
for (const QStringRef &string : stringList) {
for (const QStringView &string : stringList) {
bool ok;
realList.append(string.toDouble(&ok));
if (!ok)

View File

@ -254,7 +254,7 @@ QVariantList findPathsForModuleImports(const QVariantList &imports)
if (plugininfo.contains(dependenciesLiteral())) {
const QStringList dependencies = plugininfo.value(dependenciesLiteral()).toStringList();
for (const QString &line : dependencies) {
const auto dep = line.splitRef(QLatin1Char(' '));
const auto dep = QStringView{line}.split(QLatin1Char(' '));
QVariantMap depImport;
depImport[typeLiteral()] = moduleLiteral();
depImport[nameLiteral()] = dep[0].toString();

View File

@ -37,21 +37,21 @@ class IssueLocationWithContext
public:
IssueLocationWithContext(const QString &code, const QQmlJS::SourceLocation &location) {
int before = std::max(0,code.lastIndexOf(QLatin1Char('\n'), location.offset));
m_beforeText = code.midRef(before + 1, int(location.offset - (before + 1)));
m_issueText = code.midRef(location.offset, location.length);
m_beforeText = QStringView{code}.mid(before + 1, int(location.offset - (before + 1)));
m_issueText = QStringView{code}.mid(location.offset, location.length);
int after = code.indexOf(QLatin1Char('\n'), int(location.offset + location.length));
m_afterText = code.midRef(int(location.offset + location.length),
m_afterText = QStringView{code}.mid(int(location.offset + location.length),
int(after - (location.offset+location.length)));
}
QStringRef beforeText() const { return m_beforeText; }
QStringRef issueText() const { return m_issueText; }
QStringRef afterText() const { return m_afterText; }
QStringView beforeText() const { return m_beforeText; }
QStringView issueText() const { return m_issueText; }
QStringView afterText() const { return m_afterText; }
private:
QStringRef m_beforeText;
QStringRef m_issueText;
QStringRef m_afterText;
QStringView m_beforeText;
QStringView m_issueText;
QStringView m_afterText;
};
static void writeWarning(ColorOutput *out)

View File

@ -317,7 +317,7 @@ void FindWarningVisitor::importFileOrDirectory(const QString &fileOrDirectory,
}
}
void FindWarningVisitor::importExportedNames(const QStringRef &prefix, QString name)
void FindWarningVisitor::importExportedNames(QStringView prefix, QString name)
{
QList<ScopeTree::ConstPtr> scopes;
for (;;) {
@ -780,7 +780,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob)
QString name {};
auto id = uiob->qualifiedTypeNameId;
QStringRef prefix = uiob->qualifiedTypeNameId->name;
QStringView prefix = uiob->qualifiedTypeNameId->name;
while (id) {
name += id->name.toString() + QLatin1Char('.');
id = id->next;
@ -816,7 +816,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectDefinition *uiod)
QString name {};
auto id = uiod->qualifiedTypeNameId;
QStringRef prefix = uiod->qualifiedTypeNameId->name;
QStringView prefix = uiod->qualifiedTypeNameId->name;
while (id) {
name += id->name.toString() + QLatin1Char('.');
id = id->next;

View File

@ -106,7 +106,7 @@ private:
ScopeTree::Ptr localFile2ScopeTree(const QString &filePath);
void importFileOrDirectory(const QString &directory, const QString &prefix);
void importExportedNames(const QStringRef &prefix, QString name);
void importExportedNames(QStringView prefix, QString name);
void parseHeaders(QQmlJS::AST::UiHeaderItemList *headers);
ScopeTree::Ptr parseProgram(QQmlJS::AST::Program *program, const QString &name);

View File

@ -354,7 +354,7 @@ bool QmlProfilerApplication::checkOutputFile(PendingRequest pending)
void QmlProfilerApplication::userCommand(const QString &command)
{
auto args = command.splitRef(QChar::Space, Qt::SkipEmptyParts);
auto args = QStringView{command}.split(QChar::Space, Qt::SkipEmptyParts);
if (args.isEmpty()) {
prompt();
return;

View File

@ -198,7 +198,7 @@ void QmlProfilerData::addEventType(const QQmlProfilerEventType &type)
break;
case PixmapCacheEvent: {
const QString filePath = QUrl(type.location().filename()).path();
displayName = filePath.midRef(filePath.lastIndexOf(QLatin1Char('/')) + 1)
displayName = QStringView{filePath}.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1)
+ QLatin1Char(':') + QString::number(type.detailType());
break;
}
@ -218,7 +218,7 @@ void QmlProfilerData::addEventType(const QQmlProfilerEventType &type)
displayName = QString::fromLatin1("Unknown");
} else {
const QString filePath = QUrl(eventLocation.filename()).path();
displayName = filePath.midRef(
displayName = QStringView{filePath}.mid(
filePath.lastIndexOf(QLatin1Char('/')) + 1) +
QLatin1Char(':') + QString::number(eventLocation.line());
}

View File

@ -35,10 +35,10 @@ ComponentVersion::ComponentVersion(const QString &versionString)
if (dotIdx == -1)
return;
bool ok = false;
const int maybeMajor = versionString.leftRef(dotIdx).toInt(&ok);
const int maybeMajor = QStringView{versionString}.left(dotIdx).toInt(&ok);
if (!ok)
return;
const int maybeMinor = versionString.midRef(dotIdx + 1).toInt(&ok);
const int maybeMinor = QStringView{versionString}.mid(dotIdx + 1).toInt(&ok);
if (!ok)
return;
m_version = QTypeRevision::fromVersion(maybeMajor, maybeMinor);