Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the 'Match similar lines' option work for 3-way comparisons #1051

Merged
merged 17 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
63d1a62
Make the 'Match similar lines' option work for 3-way comparisons
sdottaka Nov 14, 2021
73487c4
Merge branch 'master' into matchsimilarlines-3way
sdottaka Nov 14, 2021
c2c1d1c
Make the 'Match similar lines' option work for 3-way comparisons (2)
sdottaka Nov 14, 2021
3168c9f
Make the 'Match similar lines' option work for 3-way comparisons (3)
sdottaka Nov 14, 2021
d648f48
Merge branch 'master' into matchsimilarlines-3way
sdottaka Nov 15, 2021
7147bc6
Make the 'Match similar lines' option work for 3-way comparisons (4)
sdottaka Nov 15, 2021
eb31003
Make the 'Match similar lines' option work for 3-way comparisons (4)
sdottaka Nov 17, 2021
a7870d1
Make the 'Match similar lines' option work for 3-way comparisons (5)
sdottaka Nov 18, 2021
a9a4451
Make the 'Match similar lines' option work for 3-way comparisons (6)
sdottaka Nov 18, 2021
f30b3c3
Make the 'Match similar lines' option work for 3-way comparisons (7)
sdottaka Nov 19, 2021
7cef588
Merge branch 'master' into matchsimilarlines-3way
sdottaka Nov 19, 2021
88ee5f8
Make the 'Match similar lines' option work for 3-way comparisons (8)
sdottaka Nov 19, 2021
16373c0
Merge branch 'master' into matchsimilarlines-3way
sdottaka Nov 19, 2021
6206e23
Make the 'Match similar lines' option work for 3-way comparisons (9)
sdottaka Nov 20, 2021
723ab50
Make the 'Match similar lines' option work for 3-way comparisons (10)
sdottaka Nov 20, 2021
bcf3aa9
Make the 'Match similar lines' option work for 3-way comparisons (11)
sdottaka Nov 20, 2021
a0d107b
Make the 'Match similar lines' option work for 3-way comparisons (12)
sdottaka Nov 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Src/Common/UnicodeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ String to_charstr(TCHAR ch)
* This function searches for a string inside another string an if found,
* replaces it with another string. Function can replace several instances
* of the string inside one string.
* @param [in] target A string containing another string to replace.
* @param [in,out] target A string containing another string to replace.
* @param [in] find A string to search and replace with another (@p replace).
* @param [in] replace A string used to replace original (@p find).
*/
Expand All @@ -119,6 +119,27 @@ void replace(String &target, const String &find, const String &replace)
}
}

/**
* @brief Replace the characters that matche characters specified in its arguments
* @param [in,out] str - A string containing another string to replace.
* @param [in] chars - characters to search for
* @param [in] rep - String to replace
*/
void replace_chars(String& str, const TCHAR* chars, const TCHAR *rep)
{
String::size_type pos = 0;
size_t replen = _tcslen(rep);
while ((pos = str.find_first_of(chars, pos)) != std::string::npos)
{
std::string::size_type posend = str.find_first_not_of(chars, pos);
if (posend != String::npos)
str.replace(pos, posend - pos, rep);
else
str.replace(pos, str.length() - pos, rep);
pos += replen;
}
}

/**
* @brief Compare two strings ignoring the character casing.
* @param [in] str1 First string to compare.
Expand Down
1 change: 1 addition & 0 deletions Src/Common/UnicodeString.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TCHAR from_charstr(const String& str);
String to_charstr(TCHAR ch);

void replace(String &target, const String &find, const String &replace);
void replace_chars(String& str, const TCHAR* chars, const TCHAR* rep);

// Comparing
int compare_nocase(const String &str1, const String &str2);
Expand Down
4 changes: 2 additions & 2 deletions Src/DiffWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static void ReplaceSpaces(std::string & str, const char *rep)
if (posend != String::npos)
str.replace(pos, posend - pos, rep);
else
str.replace(pos, 1, rep);
str.replace(pos, str.length() - pos, rep);
pos += replen;
}
}
Expand All @@ -325,7 +325,7 @@ static void ReplaceNumbers(std::string& str, const char* rep)
if (posend != String::npos)
str.replace(pos, posend - pos, rep);
else
str.replace(pos, 1, rep);
str.replace(pos, str.length() - pos, rep);
pos += replen;
}
}
Expand Down
9 changes: 7 additions & 2 deletions Src/MergeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,13 @@ int CMergeDoc::Rescan(bool &bBinary, IDENTLEVEL &identical,
m_ptBuf[nBuffer]->prepareForRescan();

// Divide diff blocks to match lines.
if (GetOptionsMgr()->GetBool(OPT_CMP_MATCH_SIMILAR_LINES) && m_nBuffers < 3)
AdjustDiffBlocks();
if (GetOptionsMgr()->GetBool(OPT_CMP_MATCH_SIMILAR_LINES))
{
if (m_nBuffers < 3)
AdjustDiffBlocks();
else
AdjustDiffBlocks3way();
}

// Analyse diff-list (updating real line-numbers)
// this operation does not change the modified flag
Expand Down
11 changes: 8 additions & 3 deletions Src/MergeDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class CMergeDoc : public CDocument, public IMergeDoc
void AddToSubstitutionFilters(CMergeEditView* pView, bool bReversed = false);
std::vector<WordDiff> GetWordDiffArrayInDiffBlock(int nDiff);
std::vector<WordDiff> GetWordDiffArray(int nLineIndex);
std::vector<WordDiff> GetWordDiffArrayInRange(const int begin[3], const int end[3]);
std::vector<WordDiff> GetWordDiffArrayInRange(const int begin[3], const int end[3], int pane1 = -1, int pane2 = -1);
void ClearWordDiffCache(int nDiff = -1);
private:
void Computelinediff(CMergeEditView *pView, CRect rc[], bool bReversed);
Expand Down Expand Up @@ -431,8 +431,13 @@ class CMergeDoc : public CDocument, public IMergeDoc
void PrimeTextBuffers();
void HideLines();
void AdjustDiffBlocks();
void AdjustDiffBlock(DiffMap & diffmap, const DIFFRANGE & diffrange, const std::vector<WordDiff>& worddiffs, int lo0, int hi0, int lo1, int hi1);
int GetMatchCost(int line0, int line1, const std::vector<WordDiff>& worddiffs);
void AdjustDiffBlocks3way();
void AdjustDiffBlock(DiffMap & diffmap, const DIFFRANGE & diffrange,
const std::vector<WordDiff>& worddiffs,
int i0, int i1, int lo0, int hi0, int lo1, int hi1);
int GetMatchCost(const DIFFRANGE& dr, int i0, int i1, int line0, int line1, const std::vector<WordDiff>& worddiffs);
OP_TYPE ComputeOpType3way(const std::vector<std::array<int, 3>>& vlines, size_t index,
const DIFFRANGE& diffrange, const DIFFOPTIONS& diffOptions);
void FlagTrivialLines();
void FlagMovedLines();
String GetFileExt(LPCTSTR sFileName, LPCTSTR sDescription) const;
Expand Down
Loading