KompareDiff2

diffparser.cpp
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// lib
10#include <komparediff2_logging.h>
11// Qt
12#include <QRegularExpression>
13
14using namespace KompareDiff2;
15
16DiffParser::DiffParser(const ModelList *list, const QStringList &diff)
17 : ParserBase(list, diff)
18{
19 // The regexps needed for context diff parsing, the rest is the same as in parserbase.cpp
20 m_contextDiffHeader1.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("\\*\\*\\* ([^\\t]+)(\\t([^\\t]+))?\\n")));
21 m_contextDiffHeader2.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("--- ([^\\t]+)(\\t([^\\t]+))?\\n")));
22}
23
24DiffParser::~DiffParser() = default;
25
26Format DiffParser::determineFormat()
27{
28 qCDebug(KOMPAREDIFF2_LOG) << "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 for (const QString &diffLine : std::as_const(m_diffLines)) {
37 qCDebug(KOMPAREDIFF2_LOG) << diffLine;
38 if (diffLine.indexOf(normalRE, 0) == 0) {
39 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from a Normal diff...";
40 return Normal;
41 }
42 if (diffLine.indexOf(unifiedRE, 0) == 0) {
43 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from a Unified diff...";
44 return Unified;
45 }
46 if (diffLine.indexOf(contextRE, 0) == 0) {
47 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from a Context diff...";
48 return Context;
49 }
50 if (diffLine.indexOf(rcsRE, 0) == 0) {
51 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from an RCS diff...";
52 return RCS;
53 }
54 if (diffLine.indexOf(edRE, 0) == 0) {
55 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from an ED diff...";
56 return Ed;
57 }
58 }
59 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from an unknown diff...";
60 return UnknownFormat;
61}
KIOCORE_EXPORT QStringList list(const QString &fileClass)
KompareDiff2 namespace.
Format
Patch format enum.
Definition global.h:16
QString anchoredPattern(QStringView expression)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:54:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.