1 /*
2 SPDX-FileCopyrightText: 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "diffparser.h"
8
9 #include <QRegExp>
10
11 #include <komparediffdebug.h>
12
13 using namespace Diff2;
14
DiffParser(const KompareModelList * list,const QStringList & diff)15 DiffParser::DiffParser(const KompareModelList* list, const QStringList& diff) : ParserBase(list, diff)
16 {
17 // The regexps needed for context diff parsing, the rest is the same as in parserbase.cpp
18 m_contextDiffHeader1.setPattern(QStringLiteral("\\*\\*\\* ([^\\t]+)(\\t([^\\t]+))?\\n"));
19 m_contextDiffHeader2.setPattern(QStringLiteral("--- ([^\\t]+)(\\t([^\\t]+))?\\n"));
20 }
21
~DiffParser()22 DiffParser::~DiffParser()
23 {
24 }
25
determineFormat()26 enum Kompare::Format DiffParser::determineFormat()
27 {
28 qCDebug(LIBKOMPAREDIFF2) << "Determining the format of the diff Diff" << m_diffLines;
29
30 QRegExp normalRE(QStringLiteral("[0-9]+[0-9,]*[acd][0-9]+[0-9,]*"));
31 QRegExp unifiedRE(QStringLiteral("^--- "));
32 QRegExp contextRE(QStringLiteral("^\\*\\*\\* "));
33 QRegExp rcsRE(QStringLiteral("^[acd][0-9]+ [0-9]+"));
34 QRegExp edRE(QStringLiteral("^[0-9]+[0-9,]*[acd]"));
35
36 QStringList::ConstIterator it = m_diffLines.begin();
37
38 while (it != m_diffLines.end())
39 {
40 qCDebug(LIBKOMPAREDIFF2) << (*it);
41 if (it->indexOf(normalRE, 0) == 0)
42 {
43 qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Normal diff...";
44 return Kompare::Normal;
45 }
46 else if (it->indexOf(unifiedRE, 0) == 0)
47 {
48 qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Unified diff...";
49 return Kompare::Unified;
50 }
51 else if (it->indexOf(contextRE, 0) == 0)
52 {
53 qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Context diff...";
54 return Kompare::Context;
55 }
56 else if (it->indexOf(rcsRE, 0) == 0)
57 {
58 qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an RCS diff...";
59 return Kompare::RCS;
60 }
61 else if (it->indexOf(edRE, 0) == 0)
62 {
63 qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an ED diff...";
64 return Kompare::Ed;
65 }
66 ++it;
67 }
68 qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an unknown diff...";
69 return Kompare::UnknownFormat;
70 }
71