diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bd9e6617827818fd043452c08c606f07b78014a0 (patch) | |
tree | 425bb4c3168f9c02f10150f235d2cb998dcc6108 /kompare/libdiff2/diffhunk.cpp | |
download | tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.tar.gz tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kompare/libdiff2/diffhunk.cpp')
-rw-r--r-- | kompare/libdiff2/diffhunk.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/kompare/libdiff2/diffhunk.cpp b/kompare/libdiff2/diffhunk.cpp new file mode 100644 index 00000000..f980dd93 --- /dev/null +++ b/kompare/libdiff2/diffhunk.cpp @@ -0,0 +1,115 @@ +/*************************************************************************** + diffhunk.cpp - description + ------------------- + begin : Sun Mar 4 2001 + copyright : (C) 2001-2003 by Otto Bruggeman + and John Firebaugh + email : otto.bruggeman@home.nl + jfirebaugh@kde.org +****************************************************************************/ + +/*************************************************************************** +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +***************************************************************************/ + + +#include "difference.h" +#include "diffhunk.h" + +using namespace Diff2; + +DiffHunk::DiffHunk( int sourceLine, int destinationLine, QString function, Type type ) : + m_sourceLine( sourceLine ), + m_destinationLine( destinationLine ), + m_function( function ), + m_type( type ) +{ +} + +DiffHunk::~DiffHunk() +{ +} + +void DiffHunk::add( Difference* diff ) +{ + m_differences.append( diff ); +} + +int DiffHunk::sourceLineCount() const +{ + DifferenceListConstIterator diffIt = m_differences.begin(); + DifferenceListConstIterator dEnd = m_differences.end(); + + int lineCount = 0; + + for ( ; diffIt != dEnd; ++diffIt ) + lineCount += (*diffIt)->sourceLineCount(); + + return lineCount; +} + +int DiffHunk::destinationLineCount() const +{ + DifferenceListConstIterator diffIt = m_differences.begin(); + DifferenceListConstIterator dEnd = m_differences.end(); + + int lineCount = 0; + + for ( ; diffIt != dEnd; ++diffIt ) + lineCount += (*diffIt)->destinationLineCount(); + + return lineCount; +} + +QString DiffHunk::recreateHunk() const +{ + QString hunk; + QString differences; + + // recreate body + DifferenceListConstIterator diffIt = m_differences.begin(); + DifferenceListConstIterator dEnd = m_differences.end(); + + int slc = 0; // source line count + int dlc = 0; // destination line count + for ( ; diffIt != dEnd; ++diffIt ) + { + switch ( (*diffIt)->type() ) + { + case Difference::Unchanged: + case Difference::Change: + slc += (*diffIt)->sourceLineCount(); + dlc += (*diffIt)->destinationLineCount(); + break; + case Difference::Insert: + dlc += (*diffIt)->destinationLineCount(); + break; + case Difference::Delete: + slc += (*diffIt)->sourceLineCount(); + break; + } + differences += (*diffIt)->recreateDifference(); + } + + // recreate header + hunk += QString::fromLatin1( "@@ -%1,%3 +%2,%4 @@" ) + .arg( m_sourceLine ) + .arg( m_destinationLine ) + .arg( slc ) + .arg( dlc ); + + if ( !m_function.isEmpty() ) + hunk += " " + m_function; + + hunk += QString::fromLatin1( "\n" ); + + hunk += differences; + + kdDebug( 8101 ) << hunk << endl; + return hunk; +} |