| 1 | // QCodeEditorcxx . . $ `<file>/src/internal/QJSONHighlighter.cpp`/ |
| 2 | #include <QJSONHighlighter>cxx . . $ `<file>/include/QJSONHighlighter`/ |
| 3 | #include <QSyntaxStyle>cxx . . $ `<file>/include/QSyntaxStyle`/ |
| 4 | |
| 5 | |
| 6 | QJSONHighlightercxx . . $ QJSONHighlighter#::QJSONHighlightercxx . . $ QJSONHighlighter#QJSONHighlighter(68d7deb16251beb9).(QTextDocumentcxx . . $ QTextDocument#* document) : |
| 7 | QStyleSyntaxHighlightercxx . . $ QStyleSyntaxHighlighter#(document), |
| 8 | m_highlightRulescxx . . $ QJSONHighlighter#m_highlightRules.(), |
| 9 | m_keyRegexcxx . . $ QJSONHighlighter#m_keyRegex.(R"(("[^\r\n:]+?")\s*:)"cxx . . $ QString#QString(85c52e162fed56f9).) |
| 10 | { |
| 11 | auto keywords = QStringListcxx . . $ QStringList#QStringList(49f6e7a06ebc5aa8).() |
| 12 | <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "null"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "true"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "false"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 13 | |
| 14 | for (auto&& keyword : keywords) |
| 15 | { |
| 16 | m_highlightRulescxx . . $ QJSONHighlighter#m_highlightRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightRule#QHighlightRule(5448daaee29b46b8). |
| 17 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).(QStringcxx . . $ QString#QString(85c52e162fed56f9).(R"(\b%1\b)").argcxx . . $ QString#arg(bc823072288cbbb5).(keyword)), |
| 18 | "Keyword"cxx . . $ QString#QString(e1217c004a86c950). |
| 19 | }); |
| 20 | } |
| 21 | |
| 22 | // Numbers |
| 23 | m_highlightRulescxx . . $ QJSONHighlighter#m_highlightRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightRule#QHighlightRule(5448daaee29b46b8). |
| 24 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).(R"(\b(0b|0x){0,1}[\d.']+\b)"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 25 | "Number"cxx . . $ QString#QString(e1217c004a86c950). |
| 26 | }); |
| 27 | |
| 28 | // Strings |
| 29 | m_highlightRulescxx . . $ QJSONHighlighter#m_highlightRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightRule#QHighlightRule(5448daaee29b46b8). |
| 30 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).(R"("[^\n"]*")"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 31 | "String"cxx . . $ QString#QString(e1217c004a86c950). |
| 32 | }); |
| 33 | } |
| 34 | |
| 35 | void QJSONHighlightercxx . . $ QJSONHighlighter#::highlightBlockcxx . . $ QJSONHighlighter#highlightBlock(3520e46b33348bf6).(const QStringcxx . . $ QString#& text) |
| 36 | { |
| 37 | for (auto&& rule : m_highlightRulescxx . . $ QJSONHighlighter#m_highlightRules.) |
| 38 | { |
| 39 | auto matchIterator = rulecxx . . $ QRegularExpressionMatchIterator#QRegularExpressionMatchIterator(42df41e057175116)..patterncxx . . $ QHighlightRule#pattern..globalMatchcxx . . $ QRegularExpression#globalMatch(72f8b242d28bebc1).(text); |
| 40 | |
| 41 | while (matchIterator.hasNextcxx . . $ QRegularExpressionMatchIterator#hasNext(50ce9a9e25b4a850).()) |
| 42 | { |
| 43 | auto match = matchIteratorcxx . . $ QRegularExpressionMatch#QRegularExpressionMatch(4c7bd13906b2250d)..nextcxx . . $ QRegularExpressionMatchIterator#next(5870644aafa115db).(); |
| 44 | |
| 45 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 46 | match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(), |
| 47 | match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(), |
| 48 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).(rulecxx . . $ QString#QString(3520e46b33348bf6)..formatNamecxx . . $ QHighlightRule#formatName.) |
| 49 | ); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Special treatment for key regex |
| 54 | auto matchIterator = m_keyRegexcxx . . $ QRegularExpressionMatchIterator#QRegularExpressionMatchIterator(42df41e057175116)..globalMatchcxx . . $ QRegularExpression#globalMatch(72f8b242d28bebc1).(text); |
| 55 | |
| 56 | while (matchIterator.hasNextcxx . . $ QRegularExpressionMatchIterator#hasNext(50ce9a9e25b4a850).()) |
| 57 | { |
| 58 | auto match = matchIteratorcxx . . $ QRegularExpressionMatch#QRegularExpressionMatch(4c7bd13906b2250d)..nextcxx . . $ QRegularExpressionMatchIterator#next(5870644aafa115db).(); |
| 59 | |
| 60 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 61 | match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(1), |
| 62 | match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(1), |
| 63 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Keyword"cxx . . $ QString#QString(e1217c004a86c950).) |
| 64 | ); |
| 65 | } |
| 66 | } |