| 1 | // QCodeEditorcxx . . $ `<file>/src/internal/QXMLHighlighter.cpp`/ |
| 2 | #include <QXMLHighlighter>cxx . . $ `<file>/include/QXMLHighlighter`/ |
| 3 | #include <QSyntaxStyle>cxx . . $ `<file>/include/QSyntaxStyle`/ |
| 4 | |
| 5 | |
| 6 | QXMLHighlightercxx . . $ QXMLHighlighter#::QXMLHighlightercxx . . $ QXMLHighlighter#QXMLHighlighter(68d7deb16251beb9).(QTextDocumentcxx . . $ QTextDocument#* document) : |
| 7 | QStyleSyntaxHighlightercxx . . $ QStyleSyntaxHighlighter#(document), |
| 8 | m_xmlKeywordRegexescxx . . $ QXMLHighlighter#m_xmlKeywordRegexes. (), |
| 9 | m_xmlElementRegexcxx . . $ QXMLHighlighter#m_xmlElementRegex. (R"(<[\s]*[/]?[\s]*([^\n][a-zA-Z-_:]*)(?=[\s/>]))"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 10 | m_xmlAttributeRegexcxx . . $ QXMLHighlighter#m_xmlAttributeRegex. (R"(\w+(?=\=))"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 11 | m_xmlValueRegexcxx . . $ QXMLHighlighter#m_xmlValueRegex. (R"("[^\n"]+"(?=\??[\s/>]))"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 12 | m_xmlCommentBeginRegexcxx . . $ QXMLHighlighter#m_xmlCommentBeginRegex.(R"(<!--)"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 13 | m_xmlCommentEndRegexcxx . . $ QXMLHighlighter#m_xmlCommentEndRegex. (R"(-->)"cxx . . $ QString#QString(85c52e162fed56f9).) |
| 14 | { |
| 15 | m_xmlKeywordRegexescxx . . $ QXMLHighlighter#m_xmlKeywordRegexes. |
| 16 | <<cxx . . $ QVector#`operator<<`(a67f761fa76cec1d). QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).("<\\?"cxx . . $ QString#QString(85c52e162fed56f9).) |
| 17 | <<cxx . . $ QVector#`operator<<`(a67f761fa76cec1d). QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).("/>"cxx . . $ QString#QString(85c52e162fed56f9).) |
| 18 | <<cxx . . $ QVector#`operator<<`(a67f761fa76cec1d). QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).(">"cxx . . $ QString#QString(85c52e162fed56f9).) |
| 19 | <<cxx . . $ QVector#`operator<<`(a67f761fa76cec1d). QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).("<"cxx . . $ QString#QString(85c52e162fed56f9).) |
| 20 | <<cxx . . $ QVector#`operator<<`(a67f761fa76cec1d). QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).("</"cxx . . $ QString#QString(85c52e162fed56f9).) |
| 21 | <<cxx . . $ QVector#`operator<<`(a67f761fa76cec1d). QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).("\\?>"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 22 | } |
| 23 | |
| 24 | void QXMLHighlightercxx . . $ QXMLHighlighter#::highlightBlockcxx . . $ QXMLHighlighter#highlightBlock(3520e46b33348bf6).(const QStringcxx . . $ QString#& text) |
| 25 | { |
| 26 | // Special treatment for xml element regex as we use captured text to emulate lookbehind |
| 27 | auto matchIterator = m_xmlElementRegexcxx . . $ QRegularExpressionMatchIterator#QRegularExpressionMatchIterator(42df41e057175116)..globalMatchcxx . . $ QRegularExpression#globalMatch(72f8b242d28bebc1).(text); |
| 28 | while (matchIterator.hasNextcxx . . $ QRegularExpressionMatchIterator#hasNext(50ce9a9e25b4a850).()) |
| 29 | { |
| 30 | auto match = matchIteratorcxx . . $ QRegularExpressionMatch#QRegularExpressionMatch(4c7bd13906b2250d)..nextcxx . . $ QRegularExpressionMatchIterator#next(5870644aafa115db).(); |
| 31 | |
| 32 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 33 | match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(), |
| 34 | match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(), |
| 35 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Keyword"cxx . . $ QString#QString(e1217c004a86c950).) // XML ELEMENT FORMAT |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | // Highlight xml keywords *after* xml elements to fix any occasional / captured into the enclosing element |
| 40 | |
| 41 | for (auto&& regex : m_xmlKeywordRegexescxx . . $ QXMLHighlighter#m_xmlKeywordRegexes.) |
| 42 | { |
| 43 | highlightByRegexcxx . . $ QXMLHighlighter#highlightByRegex(ea4fab14ee2548da).( |
| 44 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Keyword"cxx . . $ QString#QString(e1217c004a86c950).), |
| 45 | regex, |
| 46 | text |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | highlightByRegexcxx . . $ QXMLHighlighter#highlightByRegex(ea4fab14ee2548da).( |
| 51 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Text"cxx . . $ QString#QString(e1217c004a86c950).), |
| 52 | m_xmlAttributeRegexcxx . . $ QXMLHighlighter#m_xmlAttributeRegex., |
| 53 | text |
| 54 | ); |
| 55 | |
| 56 | setCurrentBlockStatecxx . . $ QSyntaxHighlighter#setCurrentBlockState(d4f767463ce0a6b3).(0); |
| 57 | |
| 58 | int startIndex = 0; |
| 59 | if (previousBlockStatecxx . . $ QSyntaxHighlighter#previousBlockState(455f465bc33b4cdf).() != 1) |
| 60 | { |
| 61 | startIndex = text.indexOfcxx . . $ QString#indexOf(44433515e1b9e5ad).(m_xmlCommentBeginRegexcxx . . $ QXMLHighlighter#m_xmlCommentBeginRegex.); |
| 62 | } |
| 63 | |
| 64 | while (startIndex >= 0) |
| 65 | { |
| 66 | auto match = m_xmlCommentEndRegexcxx . . $ QRegularExpressionMatch#QRegularExpressionMatch(4c7bd13906b2250d)..matchcxx . . $ QRegularExpression#match(76cd69b0d626af6c).(text, startIndex); |
| 67 | |
| 68 | int endIndex = match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(); |
| 69 | int commentLength = 0; |
| 70 | |
| 71 | if (endIndex == -1) |
| 72 | { |
| 73 | setCurrentBlockStatecxx . . $ QSyntaxHighlighter#setCurrentBlockState(d4f767463ce0a6b3).(1); |
| 74 | commentLength = text.lengthcxx . . $ QString#length(455f465bc33b4cdf).() - startIndex; |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | commentLength = endIndex - startIndex + match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(); |
| 79 | } |
| 80 | |
| 81 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 82 | startIndex, |
| 83 | commentLength, |
| 84 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Comment"cxx . . $ QString#QString(e1217c004a86c950).) |
| 85 | ); |
| 86 | |
| 87 | startIndex = text.indexOfcxx . . $ QString#indexOf(44433515e1b9e5ad).(m_xmlCommentBeginRegexcxx . . $ QXMLHighlighter#m_xmlCommentBeginRegex., startIndex + commentLength); |
| 88 | } |
| 89 | |
| 90 | highlightByRegexcxx . . $ QXMLHighlighter#highlightByRegex(ea4fab14ee2548da).( |
| 91 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("String"cxx . . $ QString#QString(e1217c004a86c950).), |
| 92 | m_xmlValueRegexcxx . . $ QXMLHighlighter#m_xmlValueRegex., |
| 93 | text |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | void QXMLHighlightercxx . . $ QXMLHighlighter#::highlightByRegexcxx . . $ QXMLHighlighter#highlightByRegex(ea4fab14ee2548da).(const QTextCharFormatcxx . . $ QTextCharFormat#& format, const QRegularExpressioncxx . . $ QRegularExpression#& regex, const QStringcxx . . $ QString#& text) |
| 98 | { |
| 99 | auto matchIterator = regexcxx . . $ QRegularExpressionMatchIterator#QRegularExpressionMatchIterator(42df41e057175116)..globalMatchcxx . . $ QRegularExpression#globalMatch(72f8b242d28bebc1).(text); |
| 100 | |
| 101 | while (matchIterator.hasNextcxx . . $ QRegularExpressionMatchIterator#hasNext(50ce9a9e25b4a850).()) |
| 102 | { |
| 103 | auto match = matchIteratorcxx . . $ QRegularExpressionMatch#QRegularExpressionMatch(4c7bd13906b2250d)..nextcxx . . $ QRegularExpressionMatchIterator#next(5870644aafa115db).(); |
| 104 | |
| 105 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 106 | match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(), |
| 107 | match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(), |
| 108 | format |
| 109 | ); |
| 110 | } |
| 111 | } |