1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
|
/**************************************************************************
** parserbase.cpp
** --------------
** begin : Sun Aug 4 15:05:35 2002
** Copyright 2002-2004,2009 Otto Bruggeman <bruggie@gmail.com>
** Copyright 2007,2010 Kevin Kofler <kevin.kofler@chello.at>
***************************************************************************/
/***************************************************************************
**
** 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 "parserbase.h"
#include <QtCore/QObject>
#include <kdebug.h>
#include "diffmodel.h"
#include "diffhunk.h"
#include "difference.h"
#include "komparemodellist.h"
using namespace Diff2;
ParserBase::ParserBase( const KompareModelList* list, const QStringList& diff ) :
m_diffLines( diff ),
m_currentModel( 0 ),
m_models( 0 ),
m_diffIterator( m_diffLines.begin() ),
m_singleFileDiff( false ),
m_malformed( false ),
m_list( list )
{
// kDebug(8101) << diff << endl;
// kDebug(8101) << m_diffLines << endl;
m_models = new DiffModelList();
// used in contexthunkheader
m_contextHunkHeader1.setPattern( "\\*{15} ?(.*)\\n" ); // capture is for function name
m_contextHunkHeader2.setPattern( "\\*\\*\\* ([0-9]+),([0-9]+) \\*\\*\\*\\*.*\\n" );
// used in contexthunkbody
m_contextHunkHeader3.setPattern( "--- ([0-9]+),([0-9]+) ----\\n" );
m_contextHunkBodyRemoved.setPattern( "- (.*)" );
m_contextHunkBodyAdded.setPattern ( "\\+ (.*)" );
m_contextHunkBodyChanged.setPattern( "! (.*)" );
m_contextHunkBodyContext.setPattern( " (.*)" );
m_contextHunkBodyLine.setPattern ( "[-\\+! ] (.*)" );
// This regexp sucks... i'll see what happens
m_normalDiffHeader.setPattern( "diff (?:(?:-|--)[a-zA-Z0-9=\\\"]+ )*(?:|-- +)(.*) +(.*)\\n" );
m_normalHunkHeaderAdded.setPattern ( "([0-9]+)a([0-9]+)(|,[0-9]+)(.*)\\n" );
m_normalHunkHeaderRemoved.setPattern( "([0-9]+)(|,[0-9]+)d([0-9]+)(.*)\\n" );
m_normalHunkHeaderChanged.setPattern( "([0-9]+)(|,[0-9]+)c([0-9]+)(|,[0-9]+)(.*)\\n" );
m_normalHunkBodyRemoved.setPattern ( "< (.*)" );
m_normalHunkBodyAdded.setPattern ( "> (.*)" );
m_normalHunkBodyDivider.setPattern ( "---" );
m_unifiedDiffHeader1.setPattern ( "--- ([^\\t]+)(?:\\t([^\\t]+)(?:\\t?)(.*))?\\n" );
m_unifiedDiffHeader2.setPattern ( "\\+\\+\\+ ([^\\t]+)(?:\\t([^\\t]+)(?:\\t?)(.*))?\\n" );
m_unifiedHunkHeader.setPattern ( "@@ -([0-9]+)(|,([0-9]+)) \\+([0-9]+)(|,([0-9]+)) @@(?: ?)(.*)\\n" );
m_unifiedHunkBodyAdded.setPattern ( "\\+(.*)" );
m_unifiedHunkBodyRemoved.setPattern( "-(.*)" );
m_unifiedHunkBodyContext.setPattern( " (.*)" );
m_unifiedHunkBodyLine.setPattern ( "([-+ ])(.*)" );
}
ParserBase::~ParserBase()
{
if ( m_models )
m_models = 0; // do not delete this, i pass it around...
}
enum Kompare::Format ParserBase::determineFormat()
{
// Write your own format detection routine damn it :)
return Kompare::UnknownFormat;
}
DiffModelList* ParserBase::parse( bool* malformed )
{
DiffModelList* result;
switch( determineFormat() )
{
case Kompare::Context :
result = parseContext();
break;
case Kompare::Ed :
result = parseEd();
break;
case Kompare::Normal :
result = parseNormal();
break;
case Kompare::RCS :
result = parseRCS();
break;
case Kompare::Unified :
result = parseUnified();
break;
default: // Unknown and SideBySide for now
result = 0;
break;
}
// *malformed is set to true if some hunks or parts of hunks were
// probably missed due to a malformed diff
if ( malformed )
*malformed = m_malformed;
return result;
}
bool ParserBase::parseContextDiffHeader()
{
// kDebug(8101) << "ParserBase::parseContextDiffHeader()" << endl;
bool result = false;
while ( m_diffIterator != m_diffLines.end() )
{
if ( !m_contextDiffHeader1.exactMatch( *(m_diffIterator)++ ) )
{
continue;
}
// kDebug(8101) << "Matched length Header1 = " << m_contextDiffHeader1.matchedLength() << endl;
// kDebug(8101) << "Matched string Header1 = " << m_contextDiffHeader1.cap( 0 ) << endl;
if ( m_diffIterator != m_diffLines.end() && m_contextDiffHeader2.exactMatch( *m_diffIterator ) )
{
// kDebug(8101) << "Matched length Header2 = " << m_contextDiffHeader2.matchedLength() << endl;
// kDebug(8101) << "Matched string Header2 = " << m_contextDiffHeader2.cap( 0 ) << endl;
m_currentModel = new DiffModel( m_contextDiffHeader1.cap( 1 ), m_contextDiffHeader2.cap( 1 ) );
m_currentModel->setSourceTimestamp ( m_contextDiffHeader1.cap( 3 ) );
m_currentModel->setSourceRevision ( m_contextDiffHeader1.cap( 5 ) );
m_currentModel->setDestinationTimestamp( m_contextDiffHeader2.cap( 3 ) );
m_currentModel->setDestinationRevision ( m_contextDiffHeader2.cap( 5 ) );
++m_diffIterator;
result = true;
break;
}
else
{
// We're screwed, second line does not match or is not there...
break;
}
// Do not inc the Iterator because the second line might be the first line of
// the context header and the first hit was a fluke (impossible imo)
// maybe we should return false here because the diff is broken ?
}
return result;
}
bool ParserBase::parseEdDiffHeader()
{
return false;
}
bool ParserBase::parseNormalDiffHeader()
{
// kDebug(8101) << "ParserBase::parseNormalDiffHeader()" << endl;
bool result = false;
while ( m_diffIterator != m_diffLines.end() )
{
if ( m_normalDiffHeader.exactMatch( *m_diffIterator ) )
{
// kDebug(8101) << "Matched length Header = " << m_normalDiffHeader.matchedLength() << endl;
// kDebug(8101) << "Matched string Header = " << m_normalDiffHeader.cap( 0 ) << endl;
m_currentModel = new DiffModel();
m_currentModel->setSourceFile ( m_normalDiffHeader.cap( 1 ) );
m_currentModel->setDestinationFile ( m_normalDiffHeader.cap( 2 ) );
result = true;
++m_diffIterator;
break;
}
else
{
kDebug(8101) << "No match for: " << ( *m_diffIterator ) << endl;
}
++m_diffIterator;
}
if ( result == false )
{
// Set this to the first line again and hope it is a single file diff
m_diffIterator = m_diffLines.begin();
m_currentModel = new DiffModel();
m_singleFileDiff = true;
}
return result;
}
bool ParserBase::parseRCSDiffHeader()
{
return false;
}
bool ParserBase::parseUnifiedDiffHeader()
{
// kDebug(8101) << "ParserBase::parseUnifiedDiffHeader()" << endl;
bool result = false;
while ( m_diffIterator != m_diffLines.end() ) // do not assume we start with the diffheader1 line
{
if ( !m_unifiedDiffHeader1.exactMatch( *m_diffIterator ) )
{
++m_diffIterator;
continue;
}
// kDebug(8101) << "Matched length Header1 = " << m_unifiedDiffHeader1.matchedLength() << endl;
// kDebug(8101) << "Matched string Header1 = " << m_unifiedDiffHeader1.cap( 0 ) << endl;
++m_diffIterator;
if ( m_diffIterator != m_diffLines.end() && m_unifiedDiffHeader2.exactMatch( *m_diffIterator ) )
{
m_currentModel = new DiffModel( m_unifiedDiffHeader1.cap( 1 ), m_unifiedDiffHeader2.cap( 1 ) );
m_currentModel->setSourceTimestamp( m_unifiedDiffHeader1.cap( 2 ) );
m_currentModel->setSourceRevision( m_unifiedDiffHeader1.cap( 4 ) );
m_currentModel->setDestinationTimestamp( m_unifiedDiffHeader2.cap( 2 ) );
m_currentModel->setDestinationRevision( m_unifiedDiffHeader2.cap( 4 ) );
++m_diffIterator;
result = true;
break;
}
else
{
// We're screwed, second line does not match or is not there...
break;
}
}
return result;
}
bool ParserBase::parseContextHunkHeader()
{
// kDebug(8101) << "ParserBase::parseContextHunkHeader()" << endl;
if ( m_diffIterator == m_diffLines.end() )
return false;
if ( !m_contextHunkHeader1.exactMatch( *(m_diffIterator) ) )
return false; // big fat trouble, aborting...
++m_diffIterator;
if ( m_diffIterator == m_diffLines.end() )
return false;
if ( !m_contextHunkHeader2.exactMatch( *(m_diffIterator) ) )
return false; // big fat trouble, aborting...
++m_diffIterator;
return true;
}
bool ParserBase::parseEdHunkHeader()
{
return false;
}
bool ParserBase::parseNormalHunkHeader()
{
// kDebug(8101) << "ParserBase::parseNormalHunkHeader()" << endl;
if ( m_diffIterator != m_diffLines.end() )
{
// kDebug(8101) << "Header = " << *m_diffIterator << endl;
if ( m_normalHunkHeaderAdded.exactMatch( *m_diffIterator ) )
{
m_normalDiffType = Difference::Insert;
}
else if ( m_normalHunkHeaderRemoved.exactMatch( *m_diffIterator ) )
{
m_normalDiffType = Difference::Delete;
}
else if ( m_normalHunkHeaderChanged.exactMatch( *m_diffIterator ) )
{
m_normalDiffType = Difference::Change;
}
else
return false;
++m_diffIterator;
return true;
}
return false;
}
bool ParserBase::parseRCSHunkHeader()
{
return false;
}
bool ParserBase::parseUnifiedHunkHeader()
{
// kDebug(8101) << "ParserBase::parseUnifiedHunkHeader()" << endl;
if ( m_diffIterator != m_diffLines.end() && m_unifiedHunkHeader.exactMatch( *m_diffIterator ) )
{
++m_diffIterator;
return true;
}
else
{
// kDebug(8101) << "This is not a unified hunk header : " << (*m_diffIterator) << endl;
return false;
}
}
bool ParserBase::parseContextHunkBody()
{
// kDebug(8101) << "ParserBase::parseContextHunkBody()" << endl;
// Storing the src part of the hunk for later use
QStringList oldLines;
for( ; m_diffIterator != m_diffLines.end() && m_contextHunkBodyLine.exactMatch( *m_diffIterator ); ++m_diffIterator ) {
// kDebug(8101) << "Added old line: " << *m_diffIterator << endl;
oldLines.append( *m_diffIterator );
}
if( !m_contextHunkHeader3.exactMatch( *m_diffIterator ) )
return false;
++m_diffIterator;
// Storing the dest part of the hunk for later use
QStringList newLines;
for( ; m_diffIterator != m_diffLines.end() && m_contextHunkBodyLine.exactMatch( *m_diffIterator ); ++m_diffIterator ) {
// kDebug(8101) << "Added new line: " << *m_diffIterator << endl;
newLines.append( *m_diffIterator );
}
QString function = m_contextHunkHeader1.cap( 1 );
// kDebug(8101) << "Captured function: " << function << endl;
int linenoA = m_contextHunkHeader2.cap( 1 ).toInt();
// kDebug(8101) << "Source line number: " << linenoA << endl;
int linenoB = m_contextHunkHeader3.cap( 1 ).toInt();
// kDebug(8101) << "Dest line number: " << linenoB << endl;
DiffHunk* hunk = new DiffHunk( linenoA, linenoB, function );
m_currentModel->addHunk( hunk );
QStringList::Iterator oldIt = oldLines.begin();
QStringList::Iterator newIt = newLines.begin();
Difference* diff;
while( oldIt != oldLines.end() || newIt != newLines.end() )
{
if( oldIt != oldLines.end() && m_contextHunkBodyRemoved.exactMatch( *oldIt ) )
{
// kDebug(8101) << "Delete: " << endl;
diff = new Difference( linenoA, linenoB );
diff->setType( Difference::Delete );
m_currentModel->addDiff( diff );
// kDebug(8101) << "Difference added" << endl;
hunk->add( diff );
for( ; oldIt != oldLines.end() && m_contextHunkBodyRemoved.exactMatch( *oldIt ); ++oldIt )
{
// kDebug(8101) << " " << m_contextHunkBodyRemoved.cap( 1 ) << endl;
diff->addSourceLine( m_contextHunkBodyRemoved.cap( 1 ) );
linenoA++;
}
}
else if( newIt != newLines.end() && m_contextHunkBodyAdded.exactMatch( *newIt ) )
{
// kDebug(8101) << "Insert: " << endl;
diff = new Difference( linenoA, linenoB );
diff->setType( Difference::Insert );
m_currentModel->addDiff( diff );
// kDebug(8101) << "Difference added" << endl;
hunk->add( diff );
for( ; newIt != newLines.end() && m_contextHunkBodyAdded.exactMatch( *newIt ); ++newIt )
{
// kDebug(8101) << " " << m_contextHunkBodyAdded.cap( 1 ) << endl;
diff->addDestinationLine( m_contextHunkBodyAdded.cap( 1 ) );
linenoB++;
}
}
else if( ( oldIt == oldLines.end() || m_contextHunkBodyContext.exactMatch( *oldIt ) ) &&
( newIt == newLines.end() || m_contextHunkBodyContext.exactMatch( *newIt ) ) )
{
// kDebug(8101) << "Unchanged: " << endl;
diff = new Difference( linenoA, linenoB );
// Do not add this diff with addDiff to the model... no unchanged differences allowed in there...
diff->setType( Difference::Unchanged );
hunk->add( diff );
while( ( oldIt == oldLines.end() || m_contextHunkBodyContext.exactMatch( *oldIt ) ) &&
( newIt == newLines.end() || m_contextHunkBodyContext.exactMatch( *newIt ) ) &&
( oldIt != oldLines.end() || newIt != newLines.end() ) )
{
QString l;
if( oldIt != oldLines.end() )
{
l = m_contextHunkBodyContext.cap( 1 );
// kDebug(8101) << "old: " << l << endl;
++oldIt;
}
if( newIt != newLines.end() )
{
l = m_contextHunkBodyContext.cap( 1 );
// kDebug(8101) << "new: " << l << endl;
++newIt;
}
diff->addSourceLine( l );
diff->addDestinationLine( l );
linenoA++;
linenoB++;
}
}
else if( ( oldIt != oldLines.end() && m_contextHunkBodyChanged.exactMatch( *oldIt ) ) ||
( newIt != newLines.end() && m_contextHunkBodyChanged.exactMatch( *newIt ) ) )
{
// kDebug(8101) << "Changed: " << endl;
diff = new Difference( linenoA, linenoB );
diff->setType( Difference::Change );
m_currentModel->addDiff( diff );
// kDebug(8101) << "Difference added" << endl;
hunk->add( diff );
while( oldIt != oldLines.end() && m_contextHunkBodyChanged.exactMatch( *oldIt ) )
{
// kDebug(8101) << " " << m_contextHunkBodyChanged.cap( 1 ) << endl;
diff->addSourceLine( m_contextHunkBodyChanged.cap( 1 ) );
linenoA++;
++oldIt;
}
while( newIt != newLines.end() && m_contextHunkBodyChanged.exactMatch( *newIt ) )
{
// kDebug(8101) << " " << m_contextHunkBodyChanged.cap( 1 ) << endl;
diff->addDestinationLine( m_contextHunkBodyChanged.cap( 1 ) );
linenoB++;
++newIt;
}
}
else
return false;
diff->determineInlineDifferences();
}
return true;
}
bool ParserBase::parseEdHunkBody()
{
return false;
}
bool ParserBase::parseNormalHunkBody()
{
// kDebug(8101) << "ParserBase::parseNormalHunkBody" << endl;
QString type;
int linenoA = 0, linenoB = 0;
if ( m_normalDiffType == Difference::Insert )
{
linenoA = m_normalHunkHeaderAdded.cap( 1 ).toInt();
linenoB = m_normalHunkHeaderAdded.cap( 2 ).toInt();
}
else if ( m_normalDiffType == Difference::Delete )
{
linenoA = m_normalHunkHeaderRemoved.cap( 1 ).toInt();
linenoB = m_normalHunkHeaderRemoved.cap( 3 ).toInt();
}
else if ( m_normalDiffType == Difference::Change )
{
linenoA = m_normalHunkHeaderChanged.cap( 1 ).toInt();
linenoB = m_normalHunkHeaderChanged.cap( 3 ).toInt();
}
DiffHunk* hunk = new DiffHunk( linenoA, linenoB );
m_currentModel->addHunk( hunk );
Difference* diff = new Difference( linenoA, linenoB );
hunk->add( diff );
m_currentModel->addDiff( diff );
diff->setType( m_normalDiffType );
if ( m_normalDiffType == Difference::Change || m_normalDiffType == Difference::Delete )
for( ; m_diffIterator != m_diffLines.end() && m_normalHunkBodyRemoved.exactMatch( *m_diffIterator ); ++m_diffIterator )
{
// kDebug(8101) << "Line = " << *m_diffIterator << endl;
diff->addSourceLine( m_normalHunkBodyRemoved.cap( 1 ) );
}
if ( m_normalDiffType == Difference::Change )
{
if( m_diffIterator != m_diffLines.end() && m_normalHunkBodyDivider.exactMatch( *m_diffIterator ) )
{
// kDebug(8101) << "Line = " << *m_diffIterator << endl;
++m_diffIterator;
}
else
return false;
}
if ( m_normalDiffType == Difference::Insert || m_normalDiffType == Difference::Change )
for( ; m_diffIterator != m_diffLines.end() && m_normalHunkBodyAdded.exactMatch( *m_diffIterator ); ++m_diffIterator )
{
// kDebug(8101) << "Line = " << *m_diffIterator << endl;
diff->addDestinationLine( m_normalHunkBodyAdded.cap( 1 ) );
}
return true;
}
bool ParserBase::parseRCSHunkBody()
{
return false;
}
bool ParserBase::matchesUnifiedHunkLine( QString line ) const
{
static const QChar context( ' ' );
static const QChar added ( '+' );
static const QChar removed( '-' );
QChar first = line[0];
return ( first == context || first == added || first == removed );
}
bool ParserBase::parseUnifiedHunkBody()
{
// kDebug(8101) << "ParserBase::parseUnifiedHunkBody" << endl;
int linenoA = 0, linenoB = 0;
bool wasNum;
// Fetching the stuff we need from the hunkheader regexp that was parsed in parseUnifiedHunkHeader();
linenoA = m_unifiedHunkHeader.cap( 1 ).toInt();
int lineCountA = 1, lineCountB = 1; // an ommitted line count in the header implies a line count of 1
if( !m_unifiedHunkHeader.cap( 3 ).isEmpty() )
{
lineCountA = m_unifiedHunkHeader.cap( 3 ).toInt(&wasNum);
if( !wasNum )
return false;
// If a hunk is an insertion or deletion with no context, the line number given
// is the one before the hunk. this isn't what we want, so increment it to fix this.
if(lineCountA == 0)
linenoA++;
}
linenoB = m_unifiedHunkHeader.cap( 4 ).toInt();
if( !m_unifiedHunkHeader.cap( 6 ).isEmpty() ) {
lineCountB = m_unifiedHunkHeader.cap( 6 ).toInt(&wasNum);
if( !wasNum )
return false;
if(lineCountB == 0) // see above
linenoB++;
}
QString function = m_unifiedHunkHeader.cap( 7 );
DiffHunk* hunk = new DiffHunk( linenoA, linenoB, function );
m_currentModel->addHunk( hunk );
const QStringList::ConstIterator m_diffLinesEnd = m_diffLines.end();
const QString context = QString( " " );
const QString added = QString( "+" );
const QString removed = QString( "-" );
while( m_diffIterator != m_diffLinesEnd && matchesUnifiedHunkLine( *m_diffIterator ) && (lineCountA || lineCountB) )
{
Difference* diff = new Difference( linenoA, linenoB );
hunk->add( diff );
if( (*m_diffIterator).startsWith( context ) )
{ // context
for( ; m_diffIterator != m_diffLinesEnd && (*m_diffIterator).startsWith( context ) && (lineCountA || lineCountB); ++m_diffIterator )
{
diff->addSourceLine( QString( *m_diffIterator ).remove( 0, 1 ) );
diff->addDestinationLine( QString( *m_diffIterator ).remove( 0, 1 ) );
linenoA++;
linenoB++;
--lineCountA;
--lineCountB;
}
}
else
{ // This is a real difference, not context
for( ; m_diffIterator != m_diffLinesEnd && (*m_diffIterator).startsWith( removed ) && (lineCountA || lineCountB); ++m_diffIterator )
{
diff->addSourceLine( QString( *m_diffIterator ).remove( 0, 1 ) );
linenoA++;
--lineCountA;
}
for( ; m_diffIterator != m_diffLinesEnd && (*m_diffIterator).startsWith( added ) && (lineCountA || lineCountB); ++m_diffIterator )
{
diff->addDestinationLine( QString( *m_diffIterator ).remove( 0, 1 ) );
linenoB++;
--lineCountB;
}
if ( diff->sourceLineCount() == 0 )
{
diff->setType( Difference::Insert );
// kDebug(8101) << "Insert difference" << endl;
}
else if ( diff->destinationLineCount() == 0 )
{
diff->setType( Difference::Delete );
// kDebug(8101) << "Delete difference" << endl;
}
else
{
diff->setType( Difference::Change );
// kDebug(8101) << "Change difference" << endl;
}
diff->determineInlineDifferences();
m_currentModel->addDiff( diff );
}
}
return true;
}
void ParserBase::checkHeader( const QRegExp& header )
{
if ( m_diffIterator != m_diffLines.end()
&& !header.exactMatch( *m_diffIterator )
&& !m_diffIterator->startsWith("Index: ") /* SVN diff */
&& !m_diffIterator->startsWith("diff ") /* concatenated diff */)
m_malformed = true;
}
DiffModelList* ParserBase::parseContext()
{
while ( parseContextDiffHeader() )
{
while ( parseContextHunkHeader() )
parseContextHunkBody();
if ( m_currentModel->differenceCount() > 0 )
m_models->append( m_currentModel );
checkHeader( m_contextDiffHeader1 );
}
m_models->sort();
if ( m_models->count() > 0 )
{
return m_models;
}
else
{
delete m_models;
return 0L;
}
}
DiffModelList* ParserBase::parseEd()
{
while ( parseEdDiffHeader() )
{
while ( parseEdHunkHeader() )
parseEdHunkBody();
if ( m_currentModel->differenceCount() > 0 )
m_models->append( m_currentModel );
}
m_models->sort();
if ( m_models->count() > 0 )
{
return m_models;
}
else
{
delete m_models;
return 0L;
}
}
DiffModelList* ParserBase::parseNormal()
{
while ( parseNormalDiffHeader() )
{
while ( parseNormalHunkHeader() )
parseNormalHunkBody();
if ( m_currentModel->differenceCount() > 0 )
m_models->append( m_currentModel );
checkHeader( m_normalDiffHeader );
}
if ( m_singleFileDiff )
{
while ( parseNormalHunkHeader() )
parseNormalHunkBody();
if ( m_currentModel->differenceCount() > 0 )
m_models->append( m_currentModel );
if ( m_diffIterator != m_diffLines.end() )
m_malformed = true;
}
m_models->sort();
if ( m_models->count() > 0 )
{
return m_models;
}
else
{
delete m_models;
return 0L;
}
}
DiffModelList* ParserBase::parseRCS()
{
while ( parseRCSDiffHeader() )
{
while ( parseRCSHunkHeader() )
parseRCSHunkBody();
if ( m_currentModel->differenceCount() > 0 )
m_models->append( m_currentModel );
}
m_models->sort();
if ( m_models->count() > 0 )
{
return m_models;
}
else
{
delete m_models;
return 0L;
}
}
DiffModelList* ParserBase::parseUnified()
{
while ( parseUnifiedDiffHeader() )
{
while ( parseUnifiedHunkHeader() )
parseUnifiedHunkBody();
// kDebug(8101) << "New model ready to be analyzed..." << endl;
// kDebug(8101) << " differenceCount() == " << m_currentModel->differenceCount() << endl;
if ( m_currentModel->differenceCount() > 0 )
m_models->append( m_currentModel );
checkHeader( m_unifiedDiffHeader1 );
}
m_models->sort();
if ( m_models->count() > 0 )
{
return m_models;
}
else
{
delete m_models;
return 0L;
}
}
|