• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdesdk
  • Sitemap
  • Contact Us
 

kompare

diffhunk.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                                 diffhunk.cpp
00003                                 ------------
00004         begin                   : Sun Mar 4 2001
00005         Copyright 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl>
00006         Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
00007 ****************************************************************************/
00008 
00009 /***************************************************************************
00010 **
00011 **   This program is free software; you can redistribute it and/or modify
00012 **   it under the terms of the GNU General Public License as published by
00013 **   the Free Software Foundation; either version 2 of the License, or
00014 **   (at your option) any later version.
00015 **
00016 ***************************************************************************/
00017 
00018 #include "diffhunk.h"
00019 
00020 #include "difference.h"
00021 
00022 using namespace Diff2;
00023 
00024 DiffHunk::DiffHunk( int sourceLine, int destinationLine, QString function, Type type ) :
00025     m_sourceLine( sourceLine ),
00026     m_destinationLine( destinationLine ),
00027     m_function( function ),
00028     m_type( type )
00029 {
00030 }
00031 
00032 DiffHunk::~DiffHunk()
00033 {
00034 }
00035 
00036 void DiffHunk::add( Difference* diff )
00037 {
00038     m_differences.append( diff );
00039 }
00040 
00041 int DiffHunk::sourceLineCount() const
00042 {
00043     DifferenceListConstIterator diffIt = m_differences.begin();
00044     DifferenceListConstIterator dEnd   = m_differences.end();
00045 
00046     int lineCount = 0;
00047 
00048     for ( ; diffIt != dEnd; ++diffIt )
00049         lineCount += (*diffIt)->sourceLineCount();
00050 
00051     return lineCount;
00052 }
00053 
00054 int DiffHunk::destinationLineCount() const
00055 {
00056     DifferenceListConstIterator diffIt = m_differences.begin();
00057     DifferenceListConstIterator dEnd   = m_differences.end();
00058 
00059     int lineCount = 0;
00060 
00061     for ( ; diffIt != dEnd; ++diffIt )
00062         lineCount += (*diffIt)->destinationLineCount();
00063 
00064     return lineCount;
00065 }
00066 
00067 QString DiffHunk::recreateHunk() const
00068 {
00069     QString hunk;
00070     QString differences;
00071 
00072     // recreate body
00073     DifferenceListConstIterator diffIt = m_differences.begin();
00074     DifferenceListConstIterator dEnd   = m_differences.end();
00075 
00076     int slc = 0; // source line count
00077     int dlc = 0; // destination line count
00078     for ( ; diffIt != dEnd; ++diffIt )
00079     {
00080         switch ( (*diffIt)->type() )
00081         {
00082         case Difference::Unchanged:
00083         case Difference::Change:
00084             slc += (*diffIt)->sourceLineCount();
00085             dlc += (*diffIt)->destinationLineCount();
00086             break;
00087         case Difference::Insert:
00088             dlc += (*diffIt)->destinationLineCount();
00089             break;
00090         case Difference::Delete:
00091             slc += (*diffIt)->sourceLineCount();
00092             break;
00093         }
00094         differences += (*diffIt)->recreateDifference();
00095     }
00096 
00097     // recreate header
00098     hunk += QString::fromLatin1( "@@ -%1,%3 +%2,%4 @@" )
00099             .arg( m_sourceLine )
00100             .arg( m_destinationLine )
00101             .arg( slc )
00102             .arg( dlc ); 
00103 
00104     if ( !m_function.isEmpty() )
00105         hunk += ' ' + m_function;
00106 
00107     hunk += QString::fromLatin1( "\n" );
00108 
00109     hunk += differences;
00110 
00111     kDebug( 8101 ) << hunk << endl;
00112     return hunk;
00113 }

kompare

Skip menu "kompare"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdesdk

Skip menu "kdesdk"
  • kapptemplate
  • kate
  •     kate
  • kbugbuster
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello
Generated for kdesdk by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal