genericdiffalgo.cpp
00001 /* 00002 This file is part of libtdepim. 00003 00004 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include <tqstringlist.h> 00023 00024 #include <tdelocale.h> 00025 00026 #include "genericdiffalgo.h" 00027 00028 using namespace KSync; 00029 00030 #define MAX( a, b ) ( a > b ? a : b ) 00031 00032 #ifndef KDE_USE_FINAL 00033 // With --enable-final, we get the (identical) compareString from 00034 // addresseediffalgo.cpp 00035 static bool compareString( const TQString &left, const TQString &right ) 00036 { 00037 if ( left.isEmpty() && right.isEmpty() ) 00038 return true; 00039 else 00040 return left == right; 00041 } 00042 #endif 00043 00044 GenericDiffAlgo::GenericDiffAlgo( const TQString &leftData, const TQString &rightData ) 00045 : mLeftData( leftData ), mRightData( rightData ) 00046 { 00047 } 00048 00049 void GenericDiffAlgo::run() 00050 { 00051 begin(); 00052 00053 TQStringList leftList = TQStringList::split( '\n', mLeftData, true ); 00054 TQStringList rightList = TQStringList::split( '\n', mRightData, true ); 00055 00056 uint lines = MAX( leftList.count(), rightList.count() ); 00057 for ( uint i = 0; i < lines; ++i ) { 00058 if ( i < leftList.count() && i < rightList.count() ) { 00059 if ( !compareString( leftList[ i ], rightList[ i ] ) ) 00060 conflictField( i18n( "Line %1" ).arg( i ), leftList[ i ], rightList[ i ] ); 00061 } else if ( i < leftList.count() && i >= rightList.count() ) { 00062 additionalLeftField( i18n( "Line %1" ).arg( i ), leftList[ i ] ); 00063 } else if ( i >= leftList.count() && i < rightList.count() ) { 00064 additionalRightField( i18n( "Line %1" ).arg( i ), rightList[ i ] ); 00065 } 00066 } 00067 00068 end(); 00069 } 00070