KompareDiff2

cvsdiffparser.cpp
1/*
2SPDX-FileCopyrightText: 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl>
3
4SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "cvsdiffparser.h"
8
9#include <QRegularExpression>
10
11#include <komparediffdebug.h>
12#include "komparemodellist.h"
13
14using namespace Diff2;
15
16CVSDiffParser::CVSDiffParser(const KompareModelList* list, const QStringList& diff) : ParserBase(list, diff)
17{
18 // The regexps needed for context cvs diff parsing, the rest is the same as in parserbase.cpp
19 // third capture in header1 is non optional for cvs diff, it is the revision
20 m_contextDiffHeader1.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("\\*\\*\\* ([^\\t]+)\\t([^\\t]+)\\t(.*)\\n")));
21 m_contextDiffHeader2.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("--- ([^\\t]+)\\t([^\\t]+)(|\\t(.*))\\n")));
22
23 m_normalDiffHeader.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("Index: (.*)\\n")));
24}
25
26CVSDiffParser::~CVSDiffParser()
27{
28}
29
30enum Kompare::Format CVSDiffParser::determineFormat()
31{
32// qCDebug(LIBKOMPAREDIFF2) << "Determining the format of the CVSDiff";
33
34 QRegularExpression normalRE(QStringLiteral("[0-9]+[0-9,]*[acd][0-9]+[0-9,]*"));
35 QRegularExpression unifiedRE(QStringLiteral("^--- [^\\t]+\\t"));
36 QRegularExpression contextRE(QStringLiteral("^\\*\\*\\* [^\\t]+\\t"));
37 QRegularExpression rcsRE(QStringLiteral("^[acd][0-9]+ [0-9]+"));
38 QRegularExpression edRE(QStringLiteral("^[0-9]+[0-9,]*[acd]"));
39
40 QStringList::ConstIterator it = m_diffLines.begin();
41
42 while (it != m_diffLines.end())
43 {
44 if ((*it).indexOf(normalRE, 0) == 0)
45 {
46// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Normal diff...";
47 return Kompare::Normal;
48 }
49 else if ((*it).indexOf(unifiedRE, 0) == 0)
50 {
51// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Unified diff...";
52 return Kompare::Unified;
53 }
54 else if ((*it).indexOf(contextRE, 0) == 0)
55 {
56// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Context diff...";
57 return Kompare::Context;
58 }
59 else if ((*it).indexOf(rcsRE, 0) == 0)
60 {
61// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a RCS diff...";
62 return Kompare::RCS;
63 }
64 else if ((*it).indexOf(edRE, 0) == 0)
65 {
66// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an ED diff...";
67 return Kompare::Ed;
68 }
69 ++it;
70 }
71// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an unknown diff...";
72 return Kompare::UnknownFormat;
73}
74
75bool CVSDiffParser::parseNormalDiffHeader()
76{
77 qCDebug(LIBKOMPAREDIFF2) << "CVSDiffParser::parseNormalDiffHeader()";
78 bool result = false;
79
80 QStringList::ConstIterator diffEnd = m_diffLines.end();
81
82 while (m_diffIterator != diffEnd)
83 {
84 const auto normalDiffHeaderMatch = m_normalDiffHeader.match(*m_diffIterator);
85 if (normalDiffHeaderMatch.hasMatch())
86 {
87 qCDebug(LIBKOMPAREDIFF2) << "Matched length Header = " << normalDiffHeaderMatch.capturedLength();
88 qCDebug(LIBKOMPAREDIFF2) << "Matched string Header = " << normalDiffHeaderMatch.captured(0);
89
90 m_currentModel = new DiffModel();
91 m_currentModel->setSourceFile(normalDiffHeaderMatch.captured(1));
92 m_currentModel->setDestinationFile(normalDiffHeaderMatch.captured(1));
93
94 result = true;
95
96 ++m_diffIterator;
97 break;
98 }
99 else
100 {
101 qCDebug(LIBKOMPAREDIFF2) << "No match for: " << (*m_diffIterator);
102 }
103 ++m_diffIterator;
104 }
105
106 if (result == false)
107 {
108 // Set this to the first line again and hope it is a single file diff
109 m_diffIterator = m_diffLines.begin();
110 m_currentModel = new DiffModel();
111 m_singleFileDiff = true;
112 }
113
114 return result;
115}
116
117
118bool CVSDiffParser::parseEdDiffHeader()
119{
120 return false;
121}
122
123bool CVSDiffParser::parseRCSDiffHeader()
124{
125 return false;
126}
127
128bool CVSDiffParser::parseEdHunkHeader()
129{
130 return false;
131}
132
133bool CVSDiffParser::parseRCSHunkHeader()
134{
135 return false;
136}
137
138bool CVSDiffParser::parseEdHunkBody()
139{
140 return false;
141}
142
143bool CVSDiffParser::parseRCSHunkBody()
144{
145 return false;
146}
A model describing the differences between two files.
Definition diffmodel.h:26
Diff2 namespace.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
Format
Patch format enum.
Definition kompare.h:26
typedef ConstIterator
iterator begin()
iterator end()
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, MatchType matchType, MatchOptions matchOptions) const const
QString anchoredPattern(QStringView expression)
qsizetype capturedLength(QStringView name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:10:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.