MCPcopy Create free account
hub / github.com/WinMerge/winmerge / GetWordDiffArray

Method GetWordDiffArray

Src/MergeDocLineDiffs.cpp:445–501  ·  view source on GitHub ↗

* @brief Return array of differences in specified line * This is used by algorithm for line diff coloring * (Line diff coloring is distinct from the selection highlight code) */

Source from the content-addressed store, hash-verified

443 * (Line diff coloring is distinct from the selection highlight code)
444 */
445std::vector<WordDiff> CMergeDoc::GetWordDiffArray(int nLineIndex, bool ignoreDiffOptions/*=false*/)
446{
447 int file;
448 DIFFRANGE cd;
449 std::vector<WordDiff> worddiffs;
450
451 for (file = 0; file < m_nBuffers; file++)
452 {
453 if (nLineIndex >= m_ptBuf[file]->GetLineCount())
454 return worddiffs;
455 }
456
457 int nDiff = m_diffList.LineToDiff(nLineIndex);
458 if (nDiff == -1)
459 return worddiffs;
460 if (!ignoreDiffOptions)
461 {
462 std::map<int, std::vector<WordDiff> >::iterator itmap = m_cacheWordDiffs.find(nDiff);
463 if (itmap != m_cacheWordDiffs.end())
464 {
465 worddiffs.resize((*itmap).second.size());
466 std::copy((*itmap).second.begin(), (*itmap).second.end(), worddiffs.begin());
467 return worddiffs;
468 }
469 }
470
471 m_diffList.GetDiff(nDiff, cd);
472
473 bool diffPerLine = IsDiffPerLine(m_ptBuf[0]->GetTableEditing(), cd);
474
475 int nLineBegin[3]{}, nLineEnd[3]{};
476 if (!diffPerLine)
477 {
478 for (int pane = 0; pane < m_nBuffers; ++pane)
479 {
480 nLineBegin[pane] = cd.dbegin;
481 nLineEnd[pane] = cd.dend;
482 }
483 }
484 else
485 {
486 for (int pane = 0; pane < m_nBuffers; ++pane)
487 {
488 nLineBegin[pane] = nLineEnd[pane] = nLineIndex;
489 }
490 }
491
492 worddiffs = GetWordDiffArrayInRange(nLineBegin, nLineEnd, ignoreDiffOptions);
493
494 if (!diffPerLine && !ignoreDiffOptions)
495 {
496 m_cacheWordDiffs[nDiff].resize(worddiffs.size());
497 std::copy(worddiffs.begin(), worddiffs.end(), m_cacheWordDiffs[nDiff].begin());
498 }
499
500 return worddiffs;
501}
502

Callers 1

Calls 8

IsDiffPerLineFunction · 0.85
LineToDiffMethod · 0.80
GetDiffMethod · 0.80
findMethod · 0.45
endMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected