MCPcopy Create free account
hub / github.com/KDE/kdiff3 / correctManualDiffAlignment

Method correctManualDiffAlignment

src/diff.cpp:766–926  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764}
765
766void Diff3LineList::correctManualDiffAlignment(ManualDiffHelpList* pManualDiffHelpList)
767{
768 if(pManualDiffHelpList->empty())
769 return;
770
771 // If a line appears unaligned in comparison to the manual alignment, correct this.
772
773 ManualDiffHelpList::iterator iMDHL;
774 for(iMDHL = pManualDiffHelpList->begin(); iMDHL != pManualDiffHelpList->end(); ++iMDHL)
775 {
776 Diff3LineList::iterator i3 = begin();
777 e_SrcSelector missingWinIdx = e_SrcSelector::None;
778 qint32 alignedSum = (!iMDHL->getLine1(e_SrcSelector::A).isValid() ? 0 : 1) + (!iMDHL->getLine1(e_SrcSelector::B).isValid() ? 0 : 1) + (!iMDHL->getLine1(e_SrcSelector::C).isValid() ? 0 : 1);
779 if(alignedSum == 2)
780 {
781 // If only A & B are aligned then let C rather be aligned with A
782 // If only A & C are aligned then let B rather be aligned with A
783 // If only B & C are aligned then let A rather be aligned with B
784 missingWinIdx = !iMDHL->getLine1(e_SrcSelector::A).isValid() ? e_SrcSelector::A : (!iMDHL->getLine1(e_SrcSelector::B).isValid() ? e_SrcSelector::B : e_SrcSelector::C);
785 }
786 else if(alignedSum <= 1)
787 {
788 return;
789 }
790
791 // At the first aligned line, move up the two other lines into new d3ls until the second input is aligned
792 // Then move up the third input until all three lines are aligned.
793 e_SrcSelector wi = e_SrcSelector::None;
794 for(; i3 != end(); ++i3)
795 {
796 for(wi = e_SrcSelector::A; wi != e_SrcSelector::Invalid; wi=nextSelector(wi))
797 {
798 if(i3->getLineInFile(wi).isValid() && iMDHL->firstLine(wi) == i3->getLineInFile(wi))
799 break;
800 }
801 if(wi != e_SrcSelector::Invalid)
802 break;
803 }
804
805 if(wi >= e_SrcSelector::A && wi <= e_SrcSelector::Max)
806 {
807 // Found manual alignment for one source
808 Diff3LineList::iterator iDest = i3;
809
810 // Move lines up until the next firstLine is found. Omit wi from move and search.
811 e_SrcSelector wi2 = e_SrcSelector::None;
812 for(; i3 != end(); ++i3)
813 {
814 for(wi2 = e_SrcSelector::A; wi2 != e_SrcSelector::Invalid; wi2 = nextSelector(wi2))
815 {
816 if(wi != wi2 && i3->getLineInFile(wi2).isValid() && iMDHL->firstLine(wi2) == i3->getLineInFile(wi2))
817 break;
818 }
819 if(wi2 == e_SrcSelector::Invalid)
820 { // Not yet found
821 // Move both others up
822 Diff3Line d3l;
823 // Move both up

Callers 2

determineFileAlignmentFunction · 0.80
mainInitMethod · 0.80

Calls 13

nextSelectorFunction · 0.85
endMethod · 0.80
getLineInFileMethod · 0.80
setLineBMethod · 0.80
getLineBMethod · 0.80
setLineCMethod · 0.80
getLineCMethod · 0.80
setLineAMethod · 0.80
getLineAMethod · 0.80
isValidMethod · 0.45
isEqualBCMethod · 0.45
isEqualACMethod · 0.45

Tested by 1

determineFileAlignmentFunction · 0.64