MCPcopy Create free account
hub / github.com/KDE/kate / inlineDiff

Function inlineDiff

apps/lib/diff/diffwidget.cpp:677–716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

675};
676
677static ChangePair inlineDiff(QStringView l, QStringView r)
678{
679 auto sitl = l.begin();
680 auto sitr = r.begin();
681 while (sitl != l.end() || sitr != r.end()) {
682 if (*sitl != *sitr) {
683 break;
684 }
685 ++sitl;
686 ++sitr;
687 }
688
689 int lStart = std::distance(l.begin(), sitl);
690 int rStart = std::distance(r.begin(), sitr);
691
692 auto eitl = l.rbegin();
693 auto eitr = r.rbegin();
694 int lcount = l.size();
695 int rcount = r.size();
696 while (eitl != l.rend() || eitr != r.rend()) {
697 if (*eitl != *eitr) {
698 break;
699 }
700 // do not allow overlap
701 if (lcount == lStart || rcount == rStart) {
702 break;
703 }
704 --lcount;
705 --rcount;
706 ++eitl;
707 ++eitr;
708 }
709
710 int lEnd = l.size() - std::distance(l.rbegin(), eitl);
711 int rEnd = r.size() - std::distance(r.rbegin(), eitr);
712
713 Change cl{.pos = lStart, .len = lEnd - lStart};
714 Change cr{.pos = rStart, .len = rEnd - rStart};
715 return {.left = cl, .right = cr};
716}
717
718// Struct representing a changed line in hunk
719struct HunkChangedLine {

Callers 1

markInlineDiffsFunction · 0.85

Calls 3

sizeMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected