MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / highlightBlock

Method highlightBlock

xml/xmlhighlighter.cpp:106–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106void XmlHighlighter::highlightBlock(const QString& text)
107{
108 int i = 0;
109 int pos = 0;
110 int brackets = 0;
111
112 state = (previousBlockState() == InElement ? ExpectAttributeOrEndOfElement : NoState);
113
114 if (previousBlockState() == InComment)
115 {
116 // search for the end of the comment
117 QRegExp expression(EXPR_COMMENT_END);
118 pos = expression.indexIn(text, i);
119
120 if (pos >= 0)
121 {
122 // end comment found
123 const int iLength = expression.matchedLength();
124 setFormat(0, iLength - 3, fmtComment);
125 setFormat(iLength - 3, 3, fmtSyntaxChar);
126 i += iLength; // skip comment
127 }
128 else
129 {
130 // in comment
131 setFormat(0, text.length(), fmtComment);
132 setCurrentBlockState(InComment);
133 return;
134 }
135 }
136
137 for (; i < text.length(); i++)
138 {
139#if QT_VERSION < 0x050000
140 switch (text.at(i).toAscii())
141#else
142 switch (text.at(i).toLatin1())
143#endif
144 {
145 case '<':
146 brackets++;
147 if (brackets == 1)
148 {
149 setFormat(i, 1, fmtSyntaxChar);
150 state = ExpectElementNameOrSlash;
151 }
152 else
153 {
154 // wrong bracket nesting
155 setFormat(i, 1, fmtError);
156 }
157 break;
158
159 case '>':
160 brackets--;
161 if (brackets == 0)
162 {
163 setFormat(i, 1, fmtSyntaxChar);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected