File indexing completed on 2024-06-16 04:17:51
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Dmitry Ivanov 0003 * 0004 * SPDX-License-Identifier: MIT 0005 */ 0006 #ifndef BASIC_XML_SYNTAX_HIGHLIGHTER_H 0007 #define BASIC_XML_SYNTAX_HIGHLIGHTER_H 0008 0009 #include <QSyntaxHighlighter> 0010 #include <QTextEdit> 0011 0012 /** 0013 * A Basic XML syntax highlighter in C++/Qt (subclass of QSyntaxHighlighter). Uses simple 0014 * regexes to highlight not very complicated XML content. 0015 * 0016 * * The primary limitations are: 0017 * * No specific handling for nested quotes within attributes 0018 * * No handling for multi-line comments 0019 * 0020 * @see https://github.com/d1vanov/basic-xml-syntax-highlighter 0021 * 0022 */ 0023 class BasicXMLSyntaxHighlighter : public QSyntaxHighlighter 0024 { 0025 Q_OBJECT 0026 public: 0027 BasicXMLSyntaxHighlighter(QObject * parent); 0028 BasicXMLSyntaxHighlighter(QTextDocument * parent); 0029 BasicXMLSyntaxHighlighter(QTextEdit * parent); 0030 0031 void setFormats(); 0032 0033 protected: 0034 void highlightBlock(const QString &text) override; 0035 0036 private: 0037 void highlightByRegex(const QTextCharFormat & format, 0038 const QRegExp & regex, const QString & text); 0039 0040 void setRegexes(); 0041 0042 0043 private: 0044 QTextCharFormat m_xmlKeywordFormat; 0045 QTextCharFormat m_xmlElementFormat; 0046 QTextCharFormat m_xmlAttributeFormat; 0047 QTextCharFormat m_xmlValueFormat; 0048 QTextCharFormat m_xmlCommentFormat; 0049 0050 QList<QRegExp> m_xmlKeywordRegexes; 0051 QRegExp m_xmlElementRegex; 0052 QRegExp m_xmlAttributeRegex; 0053 QRegExp m_xmlValueRegex; 0054 QRegExp m_xmlCommentRegex; 0055 }; 0056 0057 #endif // BASIC_XML_SYNTAX_HIGHLIGHTER_H