aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitrii Akshintsev <dmitrii.akshintsev@qt.io>2025-05-20 10:54:37 +0200
committerDmitrii Akshintsev <dmitrii.akshintsev@qt.io>2025-05-26 15:05:21 +0000
commit8ca418adee4ba2330a0c9a209e4fc10507448ecc (patch)
tree5ba32136b0075ee5b949d78177110f6e8e7b534e /src
parentc6eb31a8e17ef69c41313a7937b6bffd6c331ceb (diff)
QQmlJS::Lexer: Make Lexer::classify accept QStringView
Accept QStringView instead of QChat* and size. This will be handy in later patches to compare keywords through strings and not by characters Change-Id: Ie6750feb643614ceb37cad508e3bb0b33ea13952 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/parser/qqmljskeywords_p.h24
-rw-r--r--src/qml/parser/qqmljslexer.cpp6
-rw-r--r--src/qml/parser/qqmljslexer_p.h2
3 files changed, 16 insertions, 16 deletions
diff --git a/src/qml/parser/qqmljskeywords_p.h b/src/qml/parser/qqmljskeywords_p.h
index 72be5822a7..a6be934b13 100644
--- a/src/qml/parser/qqmljskeywords_p.h
+++ b/src/qml/parser/qqmljskeywords_p.h
@@ -21,7 +21,7 @@ QT_BEGIN_NAMESPACE
namespace QQmlJS {
-static inline int classify2(const QChar *s, int parseModeFlags) {
+static inline int classify2(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'a') {
if (s[1].unicode() == 's') {
return Lexer::T_AS;
@@ -51,7 +51,7 @@ static inline int classify2(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify3(const QChar *s, int parseModeFlags) {
+static inline int classify3(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'f') {
if (s[1].unicode() == 'o') {
if (s[2].unicode() == 'r') {
@@ -111,7 +111,7 @@ static inline int classify3(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify4(const QChar *s, int parseModeFlags) {
+static inline int classify4(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'b') {
if (s[1].unicode() == 'y') {
if (s[2].unicode() == 't') {
@@ -226,7 +226,7 @@ static inline int classify4(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify5(const QChar *s, int parseModeFlags) {
+static inline int classify5(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'b') {
if (s[1].unicode() == 'r') {
if (s[2].unicode() == 'e') {
@@ -352,7 +352,7 @@ static inline int classify5(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify6(const QChar *s, int parseModeFlags) {
+static inline int classify6(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'd') {
if (s[1].unicode() == 'e') {
if (s[2].unicode() == 'l') {
@@ -515,7 +515,7 @@ static inline int classify6(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify7(const QChar *s, int parseModeFlags) {
+static inline int classify7(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'b') {
if (s[1].unicode() == 'o') {
if (s[2].unicode() == 'o') {
@@ -607,7 +607,7 @@ static inline int classify7(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify8(const QChar *s, int parseModeFlags) {
+static inline int classify8(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'a') {
if (s[1].unicode() == 'b') {
if (s[2].unicode() == 's') {
@@ -742,7 +742,7 @@ static inline int classify8(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify9(const QChar *s, int parseModeFlags) {
+static inline int classify9(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'i') {
if (s[1].unicode() == 'n') {
if (s[2].unicode() == 't') {
@@ -822,7 +822,7 @@ static inline int classify9(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify10(const QChar *s, int parseModeFlags) {
+static inline int classify10(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 'i') {
if (s[1].unicode() == 'm') {
if (s[2].unicode() == 'p') {
@@ -866,7 +866,7 @@ static inline int classify10(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-static inline int classify12(const QChar *s, int parseModeFlags) {
+static inline int classify12(QStringView s, int parseModeFlags) {
if (s[0].unicode() == 's') {
if (s[1].unicode() == 'y') {
if (s[2].unicode() == 'n') {
@@ -895,8 +895,8 @@ static inline int classify12(const QChar *s, int parseModeFlags) {
return Lexer::T_IDENTIFIER;
}
-int Lexer::classify(const QChar *s, int n, int parseModeFlags) {
- switch (n) {
+int Lexer::classify(QStringView s, int parseModeFlags) {
+ switch (s.size()) {
case 2: return classify2(s, parseModeFlags);
case 3: return classify3(s, parseModeFlags);
case 4: return classify4(s, parseModeFlags);
diff --git a/src/qml/parser/qqmljslexer.cpp b/src/qml/parser/qqmljslexer.cpp
index 41556ac048..197e872e7a 100644
--- a/src/qml/parser/qqmljslexer.cpp
+++ b/src/qml/parser/qqmljslexer.cpp
@@ -945,12 +945,12 @@ again:
scanChar();
}
- _tokenLength = _codePtr - _tokenStartPtr - 1;
-
+ const auto token = QStringView(_tokenStartPtr, _codePtr - 1);
+ _tokenLength = token.size();
int kind = T_IDENTIFIER;
if (!identifierWithEscapeChars)
- kind = classify(_tokenStartPtr, _tokenLength, parseModeFlags());
+ kind = classify(token, parseModeFlags());
if (_engine) {
if (kind == T_IDENTIFIER && identifierWithEscapeChars)
diff --git a/src/qml/parser/qqmljslexer_p.h b/src/qml/parser/qqmljslexer_p.h
index f1fb140e37..63879ad45d 100644
--- a/src/qml/parser/qqmljslexer_p.h
+++ b/src/qml/parser/qqmljslexer_p.h
@@ -230,7 +230,7 @@ public:
void setState(const State &state);
protected:
- static int classify(const QChar *s, int n, int parseModeFlags);
+ static int classify(QStringView s, int parseModeFlags);
private:
int parseModeFlags() const;