KompareDiff2

diffparser.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 "diffparser.h"
8
9#include <QRegularExpression>
10
11#include <komparediffdebug.h>
12
13using namespace Diff2;
14
15DiffParser::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(QRegularExpression::anchoredPattern(QStringLiteral("\\*\\*\\* ([^\\t]+)(\\t([^\\t]+))?\\n")));
19 m_contextDiffHeader2.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("--- ([^\\t]+)(\\t([^\\t]+))?\\n")));
20}
21
22DiffParser::~DiffParser()
23{
24}
25
26enum Kompare::Format DiffParser::determineFormat()
27{
28 qCDebug(LIBKOMPAREDIFF2) << "Determining the format of the diff Diff" << m_diffLines;
29
30 QRegularExpression normalRE(QStringLiteral("[0-9]+[0-9,]*[acd][0-9]+[0-9,]*"));
31 QRegularExpression unifiedRE(QStringLiteral("^--- "));
32 QRegularExpression contextRE(QStringLiteral("^\\*\\*\\* "));
33 QRegularExpression rcsRE(QStringLiteral("^[acd][0-9]+ [0-9]+"));
34 QRegularExpression 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}
Diff2 namespace.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
Format
Patch format enum.
Definition kompare.h:26
typedef ConstIterator
iterator begin()
iterator end()
QString anchoredPattern(QStringView expression)
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.