Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
csshighlighter.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
6
8
9using namespace Qt::StringLiterals;
10
11namespace qdesigner_internal {
12
18
20{
22 static const int transitions[10][9] = {
29 { Quote, Quote, Quote, Quote, Quote, Quote, -1, Quote, Quote }, // Quote
30 { -1, -1, -1, -1, -1, -1, -1, -1, Comment }, // MaybeComment
32 { Comment, Comment, Comment, Comment, Comment, Comment, Comment, -1, MaybeCommentEnd } // MaybeCommentEnd
33 };
34
36 bool lastWasSlash = false;
38 if (state == -1) {
39 // As long as the text is empty, leave the state undetermined
40 if (text.isEmpty()) {
42 return;
43 }
44 // The initial state is based on the precense of a : and the absense of a {.
45 // This is because Qt style sheets support both a full stylesheet as well as
46 // an inline form with just properties.
47 state = save_state = (text.indexOf(u':') > -1 &&
48 text.indexOf(u'{') == -1) ? Property : Selector;
49 } else {
50 save_state = state>>16;
51 state &= 0x00ff;
52 }
53
54 if (state == MaybeCommentEnd) {
55 state = Comment;
56 } else if (state == MaybeComment) {
58 }
59
60 for (qsizetype i = 0; i < text.size(); ++i) {
61 int token = ALNUM;
62 const QChar c = text.at(i);
63 const char a = c.toLatin1();
64
65 if (state == Quote) {
66 if (a == '\\') {
67 lastWasSlash = true;
68 } else {
69 if (a == '\"' && !lastWasSlash) {
70 token = QUOTE;
71 }
72 lastWasSlash = false;
73 }
74 } else {
75 switch (a) {
76 case '{': token = LBRACE; break;
77 case '}': token = RBRACE; break;
78 case ':': token = COLON; break;
79 case ';': token = SEMICOLON; break;
80 case ',': token = COMMA; break;
81 case '\"': token = QUOTE; break;
82 case '/': token = SLASH; break;
83 case '*': token = STAR; break;
84 default: break;
85 }
86 }
87
89
90 if (new_state != state) {
92 || state == Quote;
94
95 if (new_state == Comment) {
96 lastIndex = i-1; // include the slash and star
97 } else {
98 lastIndex = i + ((token == ALNUM || new_state == Quote) ? 0 : 1);
99 }
100 }
101
102 if (new_state == -1) {
104 } else if (state <= Pseudo2) {
107 } else {
109 }
110 }
111
114}
115
117{
118 if (start >= text.size() || length <= 0)
119 return;
120
122
123 switch (state) {
124 case Selector:
126 break;
127 case Property:
129 break;
130 case Value:
132 break;
133 case Pseudo1:
135 break;
136 case Pseudo2:
138 break;
139 case Quote:
141 break;
142 case Comment:
143 case MaybeCommentEnd:
146 break;
147 default:
148 break;
149 }
150}
151
152} // namespace qdesigner_internal
153
154QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.