File indexing completed on 2024-04-14 05:37:13
0001 /* 0002 SPDX-FileCopyrightText: 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "diffparser.h" 0008 0009 // lib 0010 #include <komparediff2_logging.h> 0011 // Qt 0012 #include <QRegularExpression> 0013 0014 using namespace KompareDiff2; 0015 0016 DiffParser::DiffParser(const ModelList *list, const QStringList &diff) 0017 : ParserBase(list, diff) 0018 { 0019 // The regexps needed for context diff parsing, the rest is the same as in parserbase.cpp 0020 m_contextDiffHeader1.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("\\*\\*\\* ([^\\t]+)(\\t([^\\t]+))?\\n"))); 0021 m_contextDiffHeader2.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("--- ([^\\t]+)(\\t([^\\t]+))?\\n"))); 0022 } 0023 0024 DiffParser::~DiffParser() = default; 0025 0026 Format DiffParser::determineFormat() 0027 { 0028 qCDebug(KOMPAREDIFF2_LOG) << "Determining the format of the diff Diff" << m_diffLines; 0029 0030 QRegularExpression normalRE(QStringLiteral("[0-9]+[0-9,]*[acd][0-9]+[0-9,]*")); 0031 QRegularExpression unifiedRE(QStringLiteral("^--- ")); 0032 QRegularExpression contextRE(QStringLiteral("^\\*\\*\\* ")); 0033 QRegularExpression rcsRE(QStringLiteral("^[acd][0-9]+ [0-9]+")); 0034 QRegularExpression edRE(QStringLiteral("^[0-9]+[0-9,]*[acd]")); 0035 0036 for (const QString &diffLine : std::as_const(m_diffLines)) { 0037 qCDebug(KOMPAREDIFF2_LOG) << diffLine; 0038 if (diffLine.indexOf(normalRE, 0) == 0) { 0039 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from a Normal diff..."; 0040 return Normal; 0041 } 0042 if (diffLine.indexOf(unifiedRE, 0) == 0) { 0043 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from a Unified diff..."; 0044 return Unified; 0045 } 0046 if (diffLine.indexOf(contextRE, 0) == 0) { 0047 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from a Context diff..."; 0048 return Context; 0049 } 0050 if (diffLine.indexOf(rcsRE, 0) == 0) { 0051 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from an RCS diff..."; 0052 return RCS; 0053 } 0054 if (diffLine.indexOf(edRE, 0) == 0) { 0055 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from an ED diff..."; 0056 return Ed; 0057 } 0058 } 0059 qCDebug(KOMPAREDIFF2_LOG) << "Difflines are from an unknown diff..."; 0060 return UnknownFormat; 0061 }