-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsonhighlighter.h
48 lines (40 loc) · 1.22 KB
/
jsonhighlighter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*! ***********************************************************************************************
*
* \file jsonhighlighter.h
* \brief JsonHighlighter 类头/源文件。
*
* \version 0.1
* \date 2017/9/22
*
* \author Roy QIU <karoyqiu@gmail.com>
* \copyright © 2017 Roy QIU。
*
**************************************************************************************************/
#pragma once
#include <QSyntaxHighlighter>
class JsonHighlighter : public QSyntaxHighlighter
{
public:
explicit JsonHighlighter(QObject *parent);
explicit JsonHighlighter(QTextDocument *parent);
protected:
// QSyntaxHighlighter interface
virtual void highlightBlock(const QString &text) Q_DECL_OVERRIDE;
private:
void initRules();
private:
struct HighlightingRule
{
QRegularExpression pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> rules_;
QRegExp commentStartExpression;
QRegExp commentEndExpression;
QTextCharFormat keywordFormat;
QTextCharFormat classFormat;
QTextCharFormat singleLineCommentFormat;
QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat;
QTextCharFormat functionFormat;
};