KompareDiff2

parserbase.h
1/*
2 SPDX-FileCopyrightText: 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl>
3 SPDX-FileCopyrightText: 2010 Kevin Kofler <kevin.kofler@chello.at>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#ifndef KOMPAREDIFF2_PARSERBASE_H
9#define KOMPAREDIFF2_PARSERBASE_H
10
11// lib
12#include "difference.h"
13#include "global.h"
14// Qt
15#include <QRegularExpression>
16#include <QStringList>
17
18class QString;
19
20namespace KompareDiff2
21{
22
23class ModelList;
24class DiffModelList;
25class DiffModel;
26
27class ParserBase
28{
29public:
30 ParserBase(const ModelList *list, const QStringList &diff);
31 virtual ~ParserBase();
32
33 static QString escapePath(QString path);
34 static QString unescapePath(QString path);
35
36public:
37 Format format()
38 {
39 return determineFormat();
40 };
41
42 DiffModelList *parse(bool *malformed = nullptr);
43
44protected:
45 virtual bool parseContextDiffHeader();
46 virtual bool parseEdDiffHeader();
47 virtual bool parseNormalDiffHeader();
48 virtual bool parseRCSDiffHeader();
49 virtual bool parseUnifiedDiffHeader();
50
51 virtual bool parseContextHunkHeader();
52 virtual bool parseEdHunkHeader();
53 virtual bool parseNormalHunkHeader();
54 virtual bool parseRCSHunkHeader();
55 virtual bool parseUnifiedHunkHeader();
56
57 virtual bool parseContextHunkBody();
58 virtual bool parseEdHunkBody();
59 virtual bool parseNormalHunkBody();
60 virtual bool parseRCSHunkBody();
61 virtual bool parseUnifiedHunkBody();
62
63 virtual DiffModelList *parseContext();
64 virtual DiffModelList *parseEd();
65 virtual DiffModelList *parseNormal();
66 virtual DiffModelList *parseRCS();
67 virtual DiffModelList *parseUnified();
68
69protected: // Helper methods to speed things up
70 bool matchesUnifiedHunkLine(const QString &line) const;
71 void checkHeader(const QRegularExpression &header);
72
73protected:
74 /** What is format of the diff */
75 virtual Format determineFormat();
76
77protected:
78 // Regexps for context parsing
79 QRegularExpression m_contextDiffHeader1;
80 QRegularExpression m_contextDiffHeader2;
81
82 QRegularExpression m_contextHunkHeader1;
83 QRegularExpression m_contextHunkHeader2;
84 QRegularExpression m_contextHunkHeader3;
85 QRegularExpressionMatch m_contextHunkHeader1Match;
86 QRegularExpressionMatch m_contextHunkHeader2Match;
87
88 QRegularExpression m_contextHunkBodyRemoved;
89 QRegularExpression m_contextHunkBodyAdded;
90 QRegularExpression m_contextHunkBodyChanged;
91 QRegularExpression m_contextHunkBodyContext;
92 QRegularExpression m_contextHunkBodyLine; // Added for convenience
93
94 // Regexps for normal parsing
95 QRegularExpression m_normalDiffHeader;
96
97 QRegularExpression m_normalHunkHeaderAdded;
98 QRegularExpression m_normalHunkHeaderRemoved;
99 QRegularExpression m_normalHunkHeaderChanged;
100 QRegularExpressionMatch m_normalHunkHeaderAddedMatch;
101 QRegularExpressionMatch m_normalHunkHeaderRemovedMatch;
102 QRegularExpressionMatch m_normalHunkHeaderChangedMatch;
103
104 QRegularExpression m_normalHunkBodyRemoved;
105 QRegularExpression m_normalHunkBodyAdded;
106 QRegularExpression m_normalHunkBodyDivider;
107
108 Difference::Type m_normalDiffType;
109
110 // RegExps for rcs parsing
111 QRegularExpression m_rcsDiffHeader;
112
113 // Regexps for unified parsing
114 QRegularExpression m_unifiedDiffHeader1;
115 QRegularExpression m_unifiedDiffHeader2;
116
117 QRegularExpression m_unifiedHunkHeader;
118 QRegularExpressionMatch m_unifiedHunkHeaderMatch;
119
120protected:
121 const QStringList &m_diffLines;
122 DiffModel *m_currentModel = nullptr;
123 DiffModelList *m_models = nullptr;
124 QStringList::ConstIterator m_diffIterator;
125
126 bool m_singleFileDiff = false;
127 bool m_malformed = false;
128
129protected:
130 const ModelList *m_list;
131};
132
133} // End of namespace KompareDiff2
134
135#endif
KompareDiff2 namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:50:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.