| 216 | } |
| 217 | |
| 218 | void Highlighter::highlightBlock(const QString &text) |
| 219 | { |
| 220 | for (const HighlightingRule &rule : utils::as_const(mHighlightingRulesWithSymbols)) { |
| 221 | QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); |
| 222 | while (matchIterator.hasNext()) { |
| 223 | QRegularExpressionMatch match = matchIterator.next(); |
| 224 | setFormat(match.capturedStart(), match.capturedLength(), rule.format); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | setCurrentBlockState(0); |
| 229 | |
| 230 | int startIndex = 0; |
| 231 | if (previousBlockState() != 1) |
| 232 | startIndex = text.indexOf(mCommentStartExpression); |
| 233 | |
| 234 | while (startIndex >= 0) { |
| 235 | QRegularExpressionMatch match = mCommentEndExpression.match(text, startIndex); |
| 236 | const int endIndex = match.capturedStart(); |
| 237 | int commentLength = 0; |
| 238 | if (endIndex == -1) { |
| 239 | setCurrentBlockState(1); |
| 240 | commentLength = text.length() - startIndex; |
| 241 | } else { |
| 242 | commentLength = endIndex - startIndex |
| 243 | + match.capturedLength(); |
| 244 | } |
| 245 | setFormat(startIndex, commentLength, mMultiLineCommentFormat); |
| 246 | startIndex = text.indexOf(mCommentStartExpression, startIndex + commentLength); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | void Highlighter::applyFormat(HighlightingRule &rule) const |
| 251 | { |