-
Notifications
You must be signed in to change notification settings - Fork 1
/
xmlhighlighter.hpp
83 lines (70 loc) · 2.08 KB
/
xmlhighlighter.hpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/****************************************************************************
**
** Copyright (C) 2006 J-P Nurmi. All rights reserved.
**
** The used XML syntax highlighting principles have been adapted from
** KXESyntaxHighlighter, which is part of KXML Editor 1.1.4,
** (C) 2003 by The KXMLEditor Team (http://kxmleditor.sourceforge.net).
**
** This file may be used under the terms of the GPL Version 2, June 1991.
** For details, see http://www.gnu.org/licenses/gpl.html
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#pragma once
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QTextEdit>
#include <QRegExp>
class XmlHighlighter : public QSyntaxHighlighter
{
private:
// parser state
enum ParsingState
{
NoState = -1,
ExpectElementNameOrSlash,
ExpectElementName,
ExpectAttributeOrEndOfElement,
ExpectEqual,
ExpectAttributeValue,
InComment,
InCdata,
InElement
};
private:
// formatters
QTextCharFormat fmtSyntaxChar;
QTextCharFormat fmtElementName;
QTextCharFormat fmtComment;
QTextCharFormat fmtAttributeName;
QTextCharFormat fmtAttributeValue;
QTextCharFormat fmtError;
QTextCharFormat fmtOther;
// regular expressions
QRegExp regexp_comment;
QRegExp regexp_comment_begin;
QRegExp regexp_comment_end;
QRegExp regexp_cdata;
QRegExp regexp_cdata_begin;
QRegExp regexp_cdata_end;
QRegExp regexp_attrib;
QRegExp regexp_name;
private:
// initialization
void init();
protected:
// overrided method
virtual void highlightBlock(const QString& rstrText);
// overrided method
int processDefaultText(int i, const QString& rstrText, ParsingState &state);
public:
// constructor
XmlHighlighter(QObject* parent);
// constructor
XmlHighlighter(QTextDocument* parent);
// constructor
XmlHighlighter(QTextEdit* parent);
};