From 33a7f5ee4d8d4dc197100e3cda141063b89f74e6 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 2 Jun 2020 16:08:59 +0200 Subject: QtQml: Use unicode character literals This avoids the warnings on conversion to QChar. Change-Id: Ib774f24592d6f09a531c60bb6fa6e5bdbec88120 Reviewed-by: Fabian Kosmale --- src/3rdparty/masm/yarr/YarrSyntaxChecker.cpp | 2 +- src/qml/jsruntime/qv4dateobject.cpp | 20 +- src/qml/jsruntime/qv4globalobject.cpp | 10 +- src/qml/jsruntime/qv4jsonobject.cpp | 112 ++++----- src/qml/jsruntime/qv4regexpobject.cpp | 2 +- src/qml/parser/qqmljslexer.cpp | 331 +++++++++++++-------------- src/qml/qml/qqmlmetatype.cpp | 6 +- src/qml/qml/qqmlproperty.cpp | 8 +- src/qml/qml/qqmltypedata.cpp | 4 +- src/qml/types/qqmlconnections.cpp | 3 +- 10 files changed, 248 insertions(+), 250 deletions(-) diff --git a/src/3rdparty/masm/yarr/YarrSyntaxChecker.cpp b/src/3rdparty/masm/yarr/YarrSyntaxChecker.cpp index 358cc94d6b..821284b7b1 100644 --- a/src/3rdparty/masm/yarr/YarrSyntaxChecker.cpp +++ b/src/3rdparty/masm/yarr/YarrSyntaxChecker.cpp @@ -58,7 +58,7 @@ public: ErrorCode checkSyntax(const String& pattern, const String& flags) { SyntaxChecker syntaxChecker; - return parse(syntaxChecker, pattern, flags.contains('u')); + return parse(syntaxChecker, pattern, flags.contains(u'u')); } }} // JSC::Yarr diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index bebcbd7e44..310d393c12 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -452,16 +452,16 @@ static inline double ParseString(const QString &s, double localTZA) bool seenZ = false; // Have seen zone, i.e. +HH:mm or literal Z. bool error = false; - if (*ch == '+' || *ch == '-') { + if (*ch == u'+' || *ch == u'-') { extendedYear = true; - if (*ch == '-') + if (*ch == u'-') yearSign = -1; ++ch; } for (; ch <= end && !error && format != Done; ++ch) { - if (*ch >= '0' && *ch <= '9') { + if (*ch >= u'0' && *ch <= u'9') { current *= 10; - current += ch->unicode() - '0'; + current += ch->unicode() - u'0'; ++currentSize; } else { // other char, delimits field switch (format) { @@ -507,12 +507,12 @@ static inline double ParseString(const QString &s, double localTZA) error = (currentSize != 2) || current >= 60; break; } - if (*ch == 'T') { + if (*ch == u'T') { if (format >= Hour) error = true; format = Hour; seenT = true; - } else if (*ch == '-') { + } else if (*ch == u'-') { if (format < Day) ++format; else if (format < Minute) @@ -524,19 +524,19 @@ static inline double ParseString(const QString &s, double localTZA) offsetSign = -1; format = TimezoneHour; } - } else if (*ch == ':') { + } else if (*ch == u':') { if (format != Hour && format != Minute && format != TimezoneHour) error = true; ++format; - } else if (*ch == '.') { + } else if (*ch == u'.') { if (format != Second) error = true; ++format; - } else if (*ch == '+') { + } else if (*ch == u'+') { if (seenZ || format < Minute || format >= TimezoneHour) error = true; format = TimezoneHour; - } else if (*ch == 'Z') { + } else if (*ch == u'Z') { if (seenZ || format < Minute || format >= TimezoneHour) error = true; else diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index 1b47620572..7fa32da8aa 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -80,13 +80,13 @@ static QString escape(const QString &input) || (uc == 0x5F)) { output.append(QChar(uc)); } else { - output.append('%'); + output.append(u'%'); output.append(QLatin1Char(toHexUpper(uc >> 4))); output.append(QLatin1Char(toHexUpper(uc))); } } else { - output.append('%'); - output.append('u'); + output.append(u'%'); + output.append(u'u'); output.append(QLatin1Char(toHexUpper(uc >> 12))); output.append(QLatin1Char(toHexUpper(uc >> 8))); output.append(QLatin1Char(toHexUpper(uc >> 4))); @@ -104,9 +104,9 @@ static QString unescape(const QString &input) const int length = input.length(); while (i < length) { QChar c = input.at(i++); - if ((c == '%') && (i + 1 < length)) { + if ((c == u'%') && (i + 1 < length)) { QChar a = input.at(i); - if ((a == 'u') && (i + 4 < length)) { + if ((a == u'u') && (i + 4 < length)) { int d3 = fromHex(input.at(i+1).unicode()); int d2 = fromHex(input.at(i+2).unicode()); int d1 = fromHex(input.at(i+3).unicode()); diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index ce759111f4..2007c775c4 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -332,14 +332,14 @@ bool JsonParser::parseValue(Value *val) BEGIN << "parse Value" << *json; switch ((json++)->unicode()) { - case 'n': + case u'n': if (end - json < 3) { lastError = QJsonParseError::IllegalValue; return false; } - if (*json++ == 'u' && - *json++ == 'l' && - *json++ == 'l') { + if (*json++ == u'u' && + *json++ == u'l' && + *json++ == u'l') { *val = Value::nullValue(); DEBUG << "value: null"; END; @@ -347,14 +347,14 @@ bool JsonParser::parseValue(Value *val) } lastError = QJsonParseError::IllegalValue; return false; - case 't': + case u't': if (end - json < 3) { lastError = QJsonParseError::IllegalValue; return false; } - if (*json++ == 'r' && - *json++ == 'u' && - *json++ == 'e') { + if (*json++ == u'r' && + *json++ == u'u' && + *json++ == u'e') { *val = Value::fromBoolean(true); DEBUG << "value: true"; END; @@ -362,15 +362,15 @@ bool JsonParser::parseValue(Value *val) } lastError = QJsonParseError::IllegalValue; return false; - case 'f': + case u'f': if (end - json < 4) { lastError = QJsonParseError::IllegalValue; return false; } - if (*json++ == 'a' && - *json++ == 'l' && - *json++ == 's' && - *json++ == 'e') { + if (*json++ == u'a' && + *json++ == u'l' && + *json++ == u's' && + *json++ == u'e') { *val = Value::fromBoolean(false); DEBUG << "value: false"; END; @@ -443,32 +443,32 @@ bool JsonParser::parseNumber(Value *val) bool isInt = true; // minus - if (json < end && *json == '-') + if (json < end && *json == u'-') ++json; // int = zero / ( digit1-9 *DIGIT ) - if (json < end && *json == '0') { + if (json < end && *json == u'0') { ++json; } else { - while (json < end && *json >= '0' && *json <= '9') + while (json < end && *json >= u'0' && *json <= u'9') ++json; } // frac = decimal-point 1*DIGIT - if (json < end && *json == '.') { + if (json < end && *json == u'.') { isInt = false; ++json; - while (json < end && *json >= '0' && *json <= '9') + while (json < end && *json >= u'0' && *json <= u'9') ++json; } // exp = e [ minus / plus ] 1*DIGIT - if (json < end && (*json == 'e' || *json == 'E')) { + if (json < end && (*json == u'e' || *json == u'E')) { isInt = false; ++json; - if (json < end && (*json == '-' || *json == '+')) + if (json < end && (*json == u'-' || *json == u'+')) ++json; - while (json < end && *json >= '0' && *json <= '9') + while (json < end && *json >= u'0' && *json <= u'9') ++json; } @@ -526,12 +526,12 @@ static inline bool addHexDigit(QChar digit, uint *result) { ushort d = digit.unicode(); *result <<= 4; - if (d >= '0' && d <= '9') - *result |= (d - '0'); - else if (d >= 'a' && d <= 'f') - *result |= (d - 'a') + 10; - else if (d >= 'A' && d <= 'F') - *result |= (d - 'A') + 10; + if (d >= u'0' && d <= u'9') + *result |= (d - u'0'); + else if (d >= u'a' && d <= u'f') + *result |= (d - u'a') + 10; + else if (d >= u'A' && d <= u'F') + *result |= (d - u'A') + 10; else return false; return true; @@ -546,23 +546,23 @@ static inline bool scanEscapeSequence(const QChar *&json, const QChar *end, uint DEBUG << "scan escape"; uint escaped = (json++)->unicode(); switch (escaped) { - case '"': + case u'"': *ch = '"'; break; - case '\\': + case u'\\': *ch = '\\'; break; - case '/': + case u'/': *ch = '/'; break; - case 'b': + case u'b': *ch = 0x8; break; - case 'f': + case u'f': *ch = 0xc; break; - case 'n': + case u'n': *ch = 0xa; break; - case 'r': + case u'r': *ch = 0xd; break; - case 't': + case u't': *ch = 0x9; break; - case 'u': { + case u'u': { *ch = 0; if (json > end - 4) return false; @@ -585,9 +585,9 @@ bool JsonParser::parseString(QString *string) BEGIN << "parse string stringPos=" << json; while (json < end) { - if (*json == '"') + if (*json == u'"') break; - else if (*json == '\\') { + else if (*json == u'\\') { uint ch = 0; if (!scanEscapeSequence(json, end, &ch)) { lastError = QJsonParseError::IllegalEscapeSequence; @@ -650,42 +650,42 @@ static QString quote(const QString &str) QString product; const int length = str.length(); product.reserve(length + 2); - product += QLatin1Char('"'); + product += u'"'; for (int i = 0; i < length; ++i) { QChar c = str.at(i); switch (c.unicode()) { - case '"': + case u'"': product += QLatin1String("\\\""); break; - case '\\': + case u'\\': product += QLatin1String("\\\\"); break; - case '\b': + case u'\b': product += QLatin1String("\\b"); break; - case '\f': + case u'\f': product += QLatin1String("\\f"); break; - case '\n': + case u'\n': product += QLatin1String("\\n"); break; - case '\r': + case u'\r': product += QLatin1String("\\r"); break; - case '\t': + case u'\t': product += QLatin1String("\\t"); break; default: if (c.unicode() <= 0x1f) { product += QLatin1String("\\u00"); - product += (c.unicode() > 0xf ? QLatin1Char('1') : QLatin1Char('0')) + + product += (c.unicode() > 0xf ? u'1' : u'0') + QLatin1Char("0123456789abcdef"[c.unicode() & 0xf]); } else { product += c; } } } - product += QLatin1Char('"'); + product += u'"'; return product; } @@ -764,9 +764,9 @@ QString Stringify::makeMember(const QString &key, const Value &v) { QString strP = Str(key, v); if (!strP.isEmpty()) { - QString member = quote(key) + QLatin1Char(':'); + QString member = quote(key) + u':'; if (!gap.isEmpty()) - member += QLatin1Char(' '); + member += u' '; member += strP; return member; } @@ -821,11 +821,11 @@ QString Stringify::JO(Object *o) if (partial.isEmpty()) { result = QStringLiteral("{}"); } else if (gap.isEmpty()) { - result = QLatin1Char('{') + partial.join(QLatin1Char(',')) + QLatin1Char('}'); + result = u'{' + partial.join(u',') + u'}'; } else { QString separator = QLatin1String(",\n") + indent; - result = QLatin1String("{\n") + indent + partial.join(separator) + QLatin1Char('\n') - + stepback + QLatin1Char('}'); + result = QLatin1String("{\n") + indent + partial.join(separator) + u'\n' + + stepback + u'}'; } indent = stepback; @@ -867,10 +867,10 @@ QString Stringify::JA(Object *a) if (partial.isEmpty()) { result = QStringLiteral("[]"); } else if (gap.isEmpty()) { - result = QLatin1Char('[') + partial.join(QLatin1Char(',')) + QLatin1Char(']'); + result = u'[' + partial.join(u',') + u']'; } else { QString separator = QLatin1String(",\n") + indent; - result = QLatin1String("[\n") + indent + partial.join(separator) + QLatin1Char('\n') + stepback + QLatin1Char(']'); + result = QLatin1String("[\n") + indent + partial.join(separator) + u'\n' + stepback + u']'; } indent = stepback; @@ -948,7 +948,7 @@ ReturnedValue JsonObject::method_stringify(const FunctionObject *b, const Value s = so->d()->string; if (s->isNumber()) { - stringify.gap = QString(qMin(10, (int)s->toInteger()), ' '); + stringify.gap = QString(qMin(10, (int)s->toInteger()), u' '); } else if (String *str = s->stringValue()) { stringify.gap = str->toQString().left(10); } diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 73122fbf75..c2171d7c0e 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -171,7 +171,7 @@ QString RegExpObject::toString() const p = QStringLiteral("(?:)"); } else { // escape certain parts, see ch. 15.10.4 - p.replace('/', QLatin1String("\\/")); + p.replace(u'/', QLatin1String("\\/")); } return p; } diff --git a/src/qml/parser/qqmljslexer.cpp b/src/qml/parser/qqmljslexer.cpp index 95ad9a0670..f1f6a68583 100644 --- a/src/qml/parser/qqmljslexer.cpp +++ b/src/qml/parser/qqmljslexer.cpp @@ -87,7 +87,7 @@ Lexer::Lexer(Engine *engine) , _codePtr(nullptr) , _endPtr(nullptr) , _tokenStartPtr(nullptr) - , _char(QLatin1Char('\n')) + , _char(u'\n') , _errorCode(NoError) , _currentLineNumber(0) , _currentColumnNumber(0) @@ -139,7 +139,7 @@ void Lexer::setCode(const QString &code, int lineno, bool qmlMode) _endPtr = _codePtr + code.length(); _tokenStartPtr = _codePtr; - _char = QLatin1Char('\n'); + _char = u'\n'; _errorCode = NoError; _currentLineNumber = lineno; @@ -168,7 +168,7 @@ void Lexer::setCode(const QString &code, int lineno, bool qmlMode) void Lexer::scanChar() { if (_skipLinefeed) { - Q_ASSERT(*_codePtr == QLatin1Char('\n')); + Q_ASSERT(*_codePtr == u'\n'); ++_codePtr; _skipLinefeed = false; } @@ -176,10 +176,10 @@ void Lexer::scanChar() ++_currentColumnNumber; if (isLineTerminator()) { - if (_char == QLatin1Char('\r')) { - if (_codePtr < _endPtr && *_codePtr == QLatin1Char('\n')) + if (_char == u'\r') { + if (_codePtr < _endPtr && *_codePtr == u'\n') _skipLinefeed = true; - _char = QLatin1Char('\n'); + _char = u'\n'; } ++_currentLineNumber; _currentColumnNumber = 0; @@ -233,19 +233,19 @@ inline bool isBinop(int tok) int hexDigit(QChar c) { - if (c >= QLatin1Char('0') && c <= QLatin1Char('9')) - return c.unicode() - '0'; - if (c >= QLatin1Char('a') && c <= QLatin1Char('f')) - return c.unicode() - 'a' + 10; - if (c >= QLatin1Char('A') && c <= QLatin1Char('F')) - return c.unicode() - 'A' + 10; + if (c >= u'0' && c <= u'9') + return c.unicode() - u'0'; + if (c >= u'a' && c <= u'f') + return c.unicode() - u'a' + 10; + if (c >= u'A' && c <= u'F') + return c.unicode() - u'A' + 10; return -1; } int octalDigit(QChar c) { - if (c >= QLatin1Char('0') && c <= QLatin1Char('7')) - return c.unicode() - '0'; + if (c >= u'0' && c <= u'7') + return c.unicode() - u'0'; return -1; } @@ -348,7 +348,7 @@ int Lexer::lex() uint Lexer::decodeUnicodeEscapeCharacter(bool *ok) { - Q_ASSERT(_char == QLatin1Char('u')); + Q_ASSERT(_char == u'u'); scanChar(); // skip u if (_codePtr + 4 <= _endPtr && isHexDigit(_char)) { uint codePoint = 0; @@ -363,7 +363,7 @@ uint Lexer::decodeUnicodeEscapeCharacter(bool *ok) *ok = true; return codePoint; - } else if (_codePtr < _endPtr && _char == QLatin1Char('{')) { + } else if (_codePtr < _endPtr && _char == u'{') { scanChar(); // skip '{' uint codePoint = 0; if (!isHexDigit(_char)) @@ -381,7 +381,7 @@ uint Lexer::decodeUnicodeEscapeCharacter(bool *ok) scanChar(); } - if (_char != QLatin1Char('}')) + if (_char != u'}') goto error; scanChar(); // skip '}' @@ -423,9 +423,9 @@ QChar Lexer::decodeHexEscapeCharacter(bool *ok) static inline bool isIdentifierStart(uint ch) { // fast path for ascii - if ((ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - ch == '$' || ch == '_') + if ((ch >= u'a' && ch <= u'z') || + (ch >= u'A' && ch <= u'Z') || + ch == u'$' || ch == u'_') return true; switch (QChar::category(ch)) { @@ -445,10 +445,10 @@ static inline bool isIdentifierStart(uint ch) static bool isIdentifierPart(uint ch) { // fast path for ascii - if ((ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch >= '0' && ch <= '9') || - ch == '$' || ch == '_' || + if ((ch >= u'a' && ch <= u'z') || + (ch >= u'A' && ch <= u'Z') || + (ch >= u'0' && ch <= u'9') || + ch == u'$' || ch == u'_' || ch == 0x200c /* ZWNJ */ || ch == 0x200d /* ZWJ */) return true; @@ -495,12 +495,12 @@ again: // handle comment can be called after a '/' has been read // and returns true if it actually encountered a comment auto handleComment = [this](){ - if (_char == QLatin1Char('*')) { + if (_char == u'*') { scanChar(); while (_codePtr <= _endPtr) { - if (_char == QLatin1Char('*')) { + if (_char == u'*') { scanChar(); - if (_char == QLatin1Char('/')) { + if (_char == u'/') { scanChar(); if (_engine) { @@ -514,7 +514,7 @@ again: scanChar(); } } - } else if (_char == QLatin1Char('/')) { + } else if (_char == u'/') { while (_codePtr <= _endPtr && !isLineTerminator()) { scanChar(); } @@ -556,32 +556,32 @@ again: scanChar(); switch (ch.unicode()) { - case '~': return T_TILDE; - case '}': return T_RBRACE; + case u'~': return T_TILDE; + case u'}': return T_RBRACE; - case '|': - if (_char == QLatin1Char('|')) { + case u'|': + if (_char == u'|') { scanChar(); return T_OR_OR; - } else if (_char == QLatin1Char('=')) { + } else if (_char == u'=') { scanChar(); return T_OR_EQ; } return T_OR; - case '{': return T_LBRACE; + case u'{': return T_LBRACE; - case '^': - if (_char == QLatin1Char('=')) { + case u'^': + if (_char == u'=') { scanChar(); return T_XOR_EQ; } return T_XOR; - case ']': return T_RBRACKET; - case '[': return T_LBRACKET; - case '?': { - if (_char == QLatin1Char('?')) { + case u']': return T_RBRACKET; + case u'[': return T_LBRACKET; + case u'?': { + if (_char == u'?') { scanChar(); return T_QUESTION_QUESTION; } @@ -589,48 +589,48 @@ again: return T_QUESTION; } - case '>': - if (_char == QLatin1Char('>')) { + case u'>': + if (_char == u'>') { scanChar(); - if (_char == QLatin1Char('>')) { + if (_char == u'>') { scanChar(); - if (_char == QLatin1Char('=')) { + if (_char == u'=') { scanChar(); return T_GT_GT_GT_EQ; } return T_GT_GT_GT; - } else if (_char == QLatin1Char('=')) { + } else if (_char == u'=') { scanChar(); return T_GT_GT_EQ; } return T_GT_GT; - } else if (_char == QLatin1Char('=')) { + } else if (_char == u'=') { scanChar(); return T_GE; } return T_GT; - case '=': - if (_char == QLatin1Char('=')) { + case u'=': + if (_char == u'=') { scanChar(); - if (_char == QLatin1Char('=')) { + if (_char == u'=') { scanChar(); return T_EQ_EQ_EQ; } return T_EQ_EQ; - } else if (_char == QLatin1Char('>')) { + } else if (_char == u'>') { scanChar(); return T_ARROW; } return T_EQ; - case '<': - if (_char == QLatin1Char('=')) { + case u'<': + if (_char == u'=') { scanChar(); return T_LE; - } else if (_char == QLatin1Char('<')) { + } else if (_char == u'<') { scanChar(); - if (_char == QLatin1Char('=')) { + if (_char == u'=') { scanChar(); return T_LT_LT_EQ; } @@ -638,26 +638,26 @@ again: } return T_LT; - case ';': return T_SEMICOLON; - case ':': return T_COLON; + case u';': return T_SEMICOLON; + case u':': return T_COLON; - case '/': + case u'/': if (handleComment()) goto again; - else if (_char == QLatin1Char('=')) { + else if (_char == u'=') { scanChar(); return T_DIVIDE_EQ; } return T_DIVIDE_; - case '.': + case u'.': if (_importState == ImportState::SawImport) return T_DOT; if (isDecimalDigit(_char.unicode())) return scanNumber(ch); - if (_char == QLatin1Char('.')) { + if (_char == u'.') { scanChar(); - if (_char == QLatin1Char('.')) { + if (_char == u'.') { scanChar(); return T_ELLIPSIS; } else { @@ -668,11 +668,11 @@ again: } return T_DOT; - case '-': - if (_char == QLatin1Char('=')) { + case u'-': + if (_char == u'=') { scanChar(); return T_MINUS_EQ; - } else if (_char == QLatin1Char('-')) { + } else if (_char == u'-') { scanChar(); if (_terminator && !_delimited && !_prohibitAutomaticSemicolon && _tokenKind != T_LPAREN) { @@ -684,13 +684,13 @@ again: } return T_MINUS; - case ',': return T_COMMA; + case u',': return T_COMMA; - case '+': - if (_char == QLatin1Char('=')) { + case u'+': + if (_char == u'=') { scanChar(); return T_PLUS_EQ; - } else if (_char == QLatin1Char('+')) { + } else if (_char == u'+') { scanChar(); if (_terminator && !_delimited && !_prohibitAutomaticSemicolon && _tokenKind != T_LPAREN) { @@ -702,13 +702,13 @@ again: } return T_PLUS; - case '*': - if (_char == QLatin1Char('=')) { + case u'*': + if (_char == u'=') { scanChar(); return T_STAR_EQ; - } else if (_char == QLatin1Char('*')) { + } else if (_char == u'*') { scanChar(); - if (_char == QLatin1Char('=')) { + if (_char == u'=') { scanChar(); return T_STAR_STAR_EQ; } @@ -716,32 +716,32 @@ again: } return T_STAR; - case ')': return T_RPAREN; - case '(': return T_LPAREN; + case u')': return T_RPAREN; + case u'(': return T_LPAREN; - case '@': return T_AT; + case u'@': return T_AT; - case '&': - if (_char == QLatin1Char('=')) { + case u'&': + if (_char == u'=') { scanChar(); return T_AND_EQ; - } else if (_char == QLatin1Char('&')) { + } else if (_char == u'&') { scanChar(); return T_AND_AND; } return T_AND; - case '%': - if (_char == QLatin1Char('=')) { + case u'%': + if (_char == u'=') { scanChar(); return T_REMAINDER_EQ; } return T_REMAINDER; - case '!': - if (_char == QLatin1Char('=')) { + case u'!': + if (_char == u'=') { scanChar(); - if (_char == QLatin1Char('=')) { + if (_char == u'=') { scanChar(); return T_NOT_EQ_EQ; } @@ -749,22 +749,22 @@ again: } return T_NOT; - case '`': + case u'`': _outerTemplateBraceCount.push(_bracesCount); Q_FALLTHROUGH(); - case '\'': - case '"': + case u'\'': + case u'"': return scanString(ScanStringMode(ch.unicode())); - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': + case u'0': + case u'1': + case u'2': + case u'3': + case u'4': + case u'5': + case u'6': + case u'7': + case u'8': + case u'9': if (_importState == ImportState::SawImport) return scanVersionNumber(ch); else @@ -776,7 +776,7 @@ again: if (QChar::isHighSurrogate(c) && QChar::isLowSurrogate(_char.unicode())) { c = QChar::surrogateToUcs4(ushort(c), _char.unicode()); scanChar(); - } else if (c == '\\' && _char == QLatin1Char('u')) { + } else if (c == '\\' && _char == u'u') { identifierWithEscapeChars = true; bool ok = false; c = decodeUnicodeEscapeCharacter(&ok); @@ -799,7 +799,7 @@ again: if (QChar::isHighSurrogate(c) && QChar::isLowSurrogate(_codePtr->unicode())) { scanChar(); c = QChar::surrogateToUcs4(ushort(c), _char.unicode()); - } else if (_char == QLatin1Char('\\') && _codePtr[0] == QLatin1Char('u')) { + } else if (_char == u'\\' && _codePtr[0] == u'u') { if (!identifierWithEscapeChars) { identifierWithEscapeChars = true; _tokenText.resize(0); @@ -852,11 +852,11 @@ again: continue_skipping: while (_codePtr < _endPtr && _char.isSpace()) scanChar(); - if (_char == QLatin1Char('*')) { + if (_char == u'*') { _tokenLength = _codePtr - _tokenStartPtr - 1; kind = T_FUNCTION_STAR; scanChar(); - } else if (_char == QLatin1Char('/')) { + } else if (_char == u'/') { scanChar(); if (handleComment()) goto continue_skipping; @@ -893,23 +893,23 @@ int Lexer::scanString(ScanStringMode mode) if (_engine) { while (_codePtr <= _endPtr) { if (isLineTerminator()) { - if ((quote == QLatin1Char('`') || qmlMode())) { + if ((quote == u'`' || qmlMode())) { --_currentLineNumber; // will be read again in scanChar() break; } _errorCode = IllegalCharacter; _errorMessage = QCoreApplication::translate("QQmlParser", "Stray newline in string literal"); return T_ERROR; - } else if (_char == QLatin1Char('\\')) { + } else if (_char == u'\\') { break; - } else if (_char == '$' && quote == QLatin1Char('`')) { + } else if (_char == u'$' && quote == u'`') { break; } else if (_char == quote) { _tokenSpell = _engine->midRef(startCode - _code.unicode(), _codePtr - startCode - 1); _rawString = _tokenSpell; scanChar(); - if (quote == QLatin1Char('`')) + if (quote == u'`') _bracesCount = _outerTemplateBraceCount.pop(); if (mode == TemplateHead) @@ -935,7 +935,7 @@ int Lexer::scanString(ScanStringMode mode) auto setRawString = [&](const QChar *end) { QString raw(startCode, end - startCode - 1); raw.replace(QLatin1String("\r\n"), QLatin1String("\n")); - raw.replace(QLatin1Char('\r'), QLatin1Char('\n')); + raw.replace(u'\r', u'\n'); _rawString = _engine->newStringRef(raw); }; @@ -947,11 +947,11 @@ int Lexer::scanString(ScanStringMode mode) if (_engine) { _tokenSpell = _engine->newStringRef(_tokenText); - if (quote == QLatin1Char('`')) + if (quote == u'`') setRawString(_codePtr - 1); } - if (quote == QLatin1Char('`')) + if (quote == u'`') _bracesCount = _outerTemplateBraceCount.pop(); if (mode == TemplateContinuation) @@ -960,7 +960,7 @@ int Lexer::scanString(ScanStringMode mode) return T_NO_SUBSTITUTION_TEMPLATE; return multilineStringLiteral ? T_MULTILINE_STRING_LITERAL : T_STRING_LITERAL; - } else if (quote == QLatin1Char('`') && _char == QLatin1Char('$') && *_codePtr == '{') { + } else if (quote == u'`' && _char == u'$' && *_codePtr == u'{') { scanChar(); scanChar(); _bracesCount = 1; @@ -970,7 +970,7 @@ int Lexer::scanString(ScanStringMode mode) } return (mode == TemplateHead ? T_TEMPLATE_HEAD : T_TEMPLATE_MIDDLE); - } else if (_char == QLatin1Char('\\')) { + } else if (_char == u'\\') { scanChar(); if (_codePtr > _endPtr) { _errorCode = IllegalEscapeSequence; @@ -982,7 +982,7 @@ int Lexer::scanString(ScanStringMode mode) switch (_char.unicode()) { // unicode escape sequence - case 'u': { + case u'u': { bool ok = false; uint codePoint = decodeUnicodeEscapeCharacter(&ok); if (!ok) @@ -997,7 +997,7 @@ int Lexer::scanString(ScanStringMode mode) } break; // hex escape sequence - case 'x': { + case u'x': { bool ok = false; u = decodeHexEscapeCharacter(&ok); if (!ok) { @@ -1008,38 +1008,38 @@ int Lexer::scanString(ScanStringMode mode) } break; // single character escape sequence - case '\\': u = QLatin1Char('\\'); scanChar(); break; - case '\'': u = QLatin1Char('\''); scanChar(); break; - case '\"': u = QLatin1Char('\"'); scanChar(); break; - case 'b': u = QLatin1Char('\b'); scanChar(); break; - case 'f': u = QLatin1Char('\f'); scanChar(); break; - case 'n': u = QLatin1Char('\n'); scanChar(); break; - case 'r': u = QLatin1Char('\r'); scanChar(); break; - case 't': u = QLatin1Char('\t'); scanChar(); break; - case 'v': u = QLatin1Char('\v'); scanChar(); break; - - case '0': + case u'\\': u = u'\\'; scanChar(); break; + case u'\'': u = u'\''; scanChar(); break; + case u'\"': u = u'\"'; scanChar(); break; + case u'b': u = u'\b'; scanChar(); break; + case u'f': u = u'\f'; scanChar(); break; + case u'n': u = u'\n'; scanChar(); break; + case u'r': u = u'\r'; scanChar(); break; + case u't': u = u'\t'; scanChar(); break; + case u'v': u = u'\v'; scanChar(); break; + + case u'0': if (! _codePtr->isDigit()) { scanChar(); - u = QLatin1Char('\0'); + u = u'\0'; break; } Q_FALLTHROUGH(); - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': + case u'1': + case u'2': + case u'3': + case u'4': + case u'5': + case u'6': + case u'7': + case u'8': + case u'9': _errorCode = IllegalEscapeSequence; _errorMessage = QCoreApplication::translate("QQmlParser", "Octal escape sequences are not allowed"); return T_ERROR; - case '\r': - case '\n': + case u'\r': + case u'\n': case 0x2028u: case 0x2029u: scanChar(); @@ -1065,8 +1065,8 @@ int Lexer::scanString(ScanStringMode mode) int Lexer::scanNumber(QChar ch) { - if (ch == QLatin1Char('0')) { - if (_char == QLatin1Char('x') || _char == QLatin1Char('X')) { + if (ch == u'0') { + if (_char == u'x' || _char == u'X') { ch = _char; // remember the x or X to use it in the error message below. // parse hex integer literal @@ -1090,7 +1090,7 @@ int Lexer::scanNumber(QChar ch) _tokenValue = d; return T_NUMERIC_LITERAL; - } else if (_char == QLatin1Char('o') || _char == QLatin1Char('O')) { + } else if (_char == u'o' || _char == u'O') { ch = _char; // remember the o or O to use it in the error message below. // parse octal integer literal @@ -1114,13 +1114,13 @@ int Lexer::scanNumber(QChar ch) _tokenValue = d; return T_NUMERIC_LITERAL; - } else if (_char == QLatin1Char('b') || _char == QLatin1Char('B')) { + } else if (_char == u'b' || _char == u'B') { ch = _char; // remember the b or B to use it in the error message below. // parse binary integer literal scanChar(); // consume 'b' - if (_char.unicode() != '0' && _char.unicode() != '1') { + if (_char.unicode() != u'0' && _char.unicode() != u'1') { _errorCode = IllegalNumber; _errorMessage = QCoreApplication::translate("QQmlParser", "At least one binary digit is required after '0%1'").arg(ch); return T_ERROR; @@ -1129,9 +1129,9 @@ int Lexer::scanNumber(QChar ch) double d = 0.; while (1) { int digit = 0; - if (_char.unicode() == '1') + if (_char.unicode() == u'1') digit = 1; - else if (_char.unicode() != '0') + else if (_char.unicode() != u'0') break; d *= 2; d += digit; @@ -1151,13 +1151,13 @@ int Lexer::scanNumber(QChar ch) QVarLengthArray chars; chars.append(ch.unicode()); - if (ch != QLatin1Char('.')) { + if (ch != u'.') { while (_char.isDigit()) { chars.append(_char.unicode()); scanChar(); // consume the digit } - if (_char == QLatin1Char('.')) { + if (_char == u'.') { chars.append(_char.unicode()); scanChar(); // consume `.' } @@ -1168,14 +1168,14 @@ int Lexer::scanNumber(QChar ch) scanChar(); } - if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) { - if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) && + if (_char == u'e' || _char == u'E') { + if (_codePtr[0].isDigit() || ((_codePtr[0] == u'+' || _codePtr[0] == u'-') && _codePtr[1].isDigit())) { chars.append(_char.unicode()); scanChar(); // consume `e' - if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) { + if (_char == u'+' || _char == u'-') { chars.append(_char.unicode()); scanChar(); // consume the sign } @@ -1187,7 +1187,7 @@ int Lexer::scanNumber(QChar ch) } } - chars.append('\0'); + chars.append(u'\0'); const char *begin = chars.constData(); const char *end = nullptr; @@ -1206,7 +1206,7 @@ int Lexer::scanNumber(QChar ch) int Lexer::scanVersionNumber(QChar ch) { - if (ch == QLatin1Char('0')) { + if (ch == u'0') { _tokenValue = 0; return T_VERSION_NUMBER; } @@ -1231,11 +1231,11 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) _patternFlags = 0; if (prefix == EqualPrefix) - _tokenText += QLatin1Char('='); + _tokenText += u'='; while (true) { switch (_char.unicode()) { - case '/': + case u'/': scanChar(); // scan the flags @@ -1254,7 +1254,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) _tokenLength = _codePtr - _tokenStartPtr - 1; return true; - case '\\': + case u'\\': // regular expression backslash sequence _tokenText += _char; scanChar(); @@ -1268,15 +1268,15 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) scanChar(); break; - case '[': + case u'[': // regular expression class _tokenText += _char; scanChar(); while (_codePtr <= _endPtr && ! isLineTerminator()) { - if (_char == QLatin1Char(']')) + if (_char == u']') break; - else if (_char == QLatin1Char('\\')) { + else if (_char == u'\\') { // regular expression backslash sequence _tokenText += _char; scanChar(); @@ -1294,7 +1294,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) } } - if (_char != QLatin1Char(']')) { + if (_char != u']') { _errorMessage = QCoreApplication::translate("QQmlParser", "Unterminated regular expression class"); return false; } @@ -1347,10 +1347,9 @@ bool Lexer::isIdentLetter(QChar ch) { // ASCII-biased, since all reserved words are ASCII, aand hence the // bulk of content to be parsed. - if ((ch >= QLatin1Char('a') && ch <= QLatin1Char('z')) - || (ch >= QLatin1Char('A') && ch <= QLatin1Char('Z')) - || ch == QLatin1Char('$') - || ch == QLatin1Char('_')) + if ((ch >= u'a' && ch <= u'z') + || (ch >= u'A' && ch <= u'Z') + || ch == u'$' || ch == u'_') return true; if (ch.unicode() < 128) return false; @@ -1359,19 +1358,19 @@ bool Lexer::isIdentLetter(QChar ch) bool Lexer::isDecimalDigit(ushort c) { - return (c >= '0' && c <= '9'); + return (c >= u'0' && c <= u'9'); } bool Lexer::isHexDigit(QChar c) { - return ((c >= QLatin1Char('0') && c <= QLatin1Char('9')) - || (c >= QLatin1Char('a') && c <= QLatin1Char('f')) - || (c >= QLatin1Char('A') && c <= QLatin1Char('F'))); + return ((c >= u'0' && c <= u'9') + || (c >= u'a' && c <= u'f') + || (c >= u'A' && c <= u'F')); } bool Lexer::isOctalDigit(ushort c) { - return (c >= '0' && c <= '7'); + return (c >= u'0' && c <= u'7'); } QString Lexer::tokenText() const @@ -1561,7 +1560,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error) if (_tokenKind != QQmlJSGrammar::T_DOT) break; - pathOrUri.append(QLatin1Char('.')); + pathOrUri.append(u'.'); lex(); if (tokenStartLine() != lineNumber) { @@ -1574,7 +1573,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error) version = tokenText(); lex(); if (_tokenKind == T_DOT) { - version += QLatin1Char('.'); + version += u'.'; lex(); if (_tokenKind != T_VERSION_NUMBER) { setError(QCoreApplication::translate( diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 4587ac3cc8..761016669c 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -379,7 +379,7 @@ bool checkRegistration(QQmlType::RegistrationType typeType, QQmlMetaTypeData *da int typeNameLen = typeName.length(); for (int ii = 0; ii < typeNameLen; ++ii) { - if (!(typeName.at(ii).isLetterOrNumber() || typeName.at(ii) == '_')) { + if (!(typeName.at(ii).isLetterOrNumber() || typeName.at(ii) == u'_')) { QString failure(QCoreApplication::translate("qmlRegisterType", "Invalid QML %1 name \"%2\"")); data->recordTypeRegFailure(failure.arg(registrationTypeString(typeType)).arg(typeName)); return false; @@ -846,10 +846,10 @@ QQmlType QQmlMetaType::typeForUrl(const QString &urlString, // data. if (errors) { QQmlError error; - error.setDescription(failures.join('\n')); + error.setDescription(failures.join(u'\n')); errors->prepend(error); } else { - qWarning("%s", failures.join('\n').toLatin1().constData()); + qWarning("%s", failures.join(u'\n').toLatin1().constData()); } return QQmlType(); } diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 1d95de9631..9595675ba6 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -355,16 +355,14 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) terminal = path.last(); } - if (terminal.count() >= 3 && - terminal.at(0) == QLatin1Char('o') && - terminal.at(1) == QLatin1Char('n') && - (terminal.at(2).isUpper() || terminal.at(2) == '_')) { + if (terminal.count() >= 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(); int firstNon_; int length = signalName.length(); for (firstNon_ = 0; firstNon_ < length; ++firstNon_) - if (signalName.at(firstNon_) != '_') + if (signalName.at(firstNon_) != u'_') break; signalName[firstNon_] = signalName.at(firstNon_).toLower(); diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp index 3b50027c4f..324d5a863f 100644 --- a/src/qml/qml/qqmltypedata.cpp +++ b/src/qml/qml/qqmltypedata.cpp @@ -351,7 +351,7 @@ void QQmlTypeData::done() auto objectId = containingType.lookupInlineComponentIdByName(type.type.pendingResolutionName()); if (objectId < 0) { // can be any negative number if we tentatively resolved it in QQmlImport but it actually was not an inline component const QString typeName = stringAt(it.key()); - int lastDot = typeName.lastIndexOf('.'); + int lastDot = typeName.lastIndexOf(u'.'); QList errors = type.typeData ? type.typeData->errors() : QList{}; QQmlError error; @@ -505,7 +505,7 @@ void QQmlTypeData::done() // associate inline components to root component { - auto typeName = finalUrlString().splitRef('/').last().split('.').first().toString(); + auto typeName = finalUrlString().splitRef(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 }; diff --git a/src/qml/types/qqmlconnections.cpp b/src/qml/types/qqmlconnections.cpp index c913e2d11a..676c15e01f 100644 --- a/src/qml/types/qqmlconnections.cpp +++ b/src/qml/types/qqmlconnections.cpp @@ -241,7 +241,8 @@ void QQmlConnectionsParser::verifyBindings(const QQmlRefPointerstringAt(binding->propertyNameIndex); - const bool thirdCharacterIsValid = (propName.length() >= 2) && (propName.at(2).isUpper() || propName.at(2) == '_'); + const bool thirdCharacterIsValid = (propName.length() >= 2) + && (propName.at(2).isUpper() || propName.at(2) == u'_'); if (!propName.startsWith(QLatin1String("on")) || !thirdCharacterIsValid) { error(props.at(ii), QQmlConnections::tr("Cannot assign to non-existent property \"%1\"").arg(propName)); return; -- cgit v1.2.3