File: QXMLHighlighter.hpp

package info (click to toggle)
qcodeeditor 1.0%2B1gitdc644d-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 528 kB
  • sloc: cpp: 2,502; xml: 731; python: 11; makefile: 9
file content (43 lines) | stat: -rw-r--r-- 1,008 bytes parent folder | download | duplicates (2)
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
#pragma once

// QCodeEditor
#include <QStyleSyntaxHighlighter> // Required for inheritance

// Qt
#include <QVector>
#include <QRegularExpression>

/**
 * @brief Class, that describes XML code
 * highlighter.
 */
class QXMLHighlighter : public QStyleSyntaxHighlighter
{
    Q_OBJECT
public:

    /**
     * @brief Constructor.
     * @param document Pointer to document.
     */
    explicit QXMLHighlighter(QTextDocument* document=nullptr);

protected:

    void highlightBlock(const QString& text) override;

private:

    void highlightByRegex(const QTextCharFormat& format,
                          const QRegularExpression& regex,
                          const QString& text);

    QVector<QRegularExpression> m_xmlKeywordRegexes;
    QRegularExpression          m_xmlElementRegex;
    QRegularExpression          m_xmlAttributeRegex;
    QRegularExpression          m_xmlValueRegex;
    QRegularExpression          m_xmlCommentBeginRegex;
    QRegularExpression          m_xmlCommentEndRegex;

};