NCBI C++ ToolKit
Classes | Typedefs | Enumerations | Enumerator | Functions | Variables | Friends
Diff
+ Collaboration diagram for Diff:

Classes

class  CDiffOperation
 CDiffOperation – The storage class for one diff operation. More...
 
struct  CDiffOperation::SPos
 Structure to save offset/length in the compared strings. More...
 
class  CDiffList
 CDiffList – the list of diff operations. More...
 
class  CDiffBase
 CDiffBase – Diff and compare texts (base class) More...
 
class  CDiff
 CDiff –. More...
 
class  CDiffText
 CDiffText – Diff and compare texts (line mode) More...
 
class  CDiffException
 CDiffException –. More...
 

Typedefs

typedef size_t CDiffOperation::size_type
 
typedef CDiffOperation::size_type CDiffList::size_type
 Size type definition. More...
 
typedef list< CDiffOperationCDiffList::TList
 Storage class type for the list of diff operations. More...
 
typedef CDiffOperation::size_type CDiffBase::size_type
 Type definition. More...
 
typedef unsigned int CDiff::TFlags
 Bitwise OR of "EFlags". More...
 
typedef vector< CTempStringCDiff::TDiffHalfMatchList
 Five element array for the list of strings, returned by x_DiffHalfMatch() More...
 
typedef unsigned int CDiffText::TFlags
 Bitwise OR of "Flags". More...
 

Enumerations

enum  CDiffOperation::EType { CDiffOperation::eDelete , CDiffOperation::eEqual , CDiffOperation::eInsert }
 Type of the current diff operation. More...
 
enum  CDiff::EFlags { CDiff::fNoCleanup = 1 << 0 , CDiff::fCalculateOffsets = 1 << 1 }
 Processing flags. More...
 
enum  CDiffText::EFlags { CDiffText::fCleanup = 1 << 0 , CDiffText::fCalculateOffsets = 1 << 1 , CDiffText::fIgnoreEOL = 1 << 2 , CDiffText::fRemoveEOL = 1 << 3 }
 Processing flags. More...
 
enum  CDiffException::EErrCode { CDiffException::eEmpty , CDiffException::eBadFlags }
 

Functions

 CDiffOperation::SPos::SPos (size_type p1=NPOS, size_type p2=NPOS)
 
 CDiffOperation::CDiffOperation (EType operation, CTempString str)
 Constructor. More...
 
EType CDiffOperation::GetOperation () const
 Get type of operation. More...
 
bool CDiffOperation::IsInsert (void) const
 Check type of operation. More...
 
bool CDiffOperation::IsDelete (void) const
 
bool CDiffOperation::IsEqual (void) const
 
CTempString CDiffOperation::GetString (void) const
 Get string for current operation. More...
 
size_type CDiffOperation::GetLength (void) const
 Get string length. More...
 
SPos CDiffOperation::GetOffset (void) const
 Get offset of the current difference in the original text. More...
 
SPos CDiffOperation::GetLine (void) const
 Get line number of the current difference (line-mode diff only). More...
 
bool CDiffOperation::operator== (const CDiffOperation &diff_op) const
 Compare substrings and operation types only, all other attributes (offset, row, col and etc) are not used in comparison. More...
 
bool CDiffOperation::operator!= (const CDiffOperation &diff_op) const
 
void CDiffOperation::SetOperation (EType operation)
 
void CDiffOperation::SetString (CTempString str, size_type len=NPOS)
 
void CDiffOperation::SetLength (size_type length)
 
void CDiffOperation::SetOffset (SPos offset)
 
void CDiffOperation::SetLine (SPos line)
 
 CDiffList::CDiffList (void)
 Constructor. More...
 
size_type CDiffList::GetEditDistance (void) const
 Compute the edit distance (Levenshtein distance). More...
 
CTempString CDiffList::GetLongestCommonSubstring (void) const
 Find the longest common substring for current difference list. More...
 
void CDiffList::CleanupAndMerge (void)
 Reorder and merge like edit sections, merge equalities. More...
 
void CDiffList::CalculateOffsets (void)
 Calculate offsets for all substrings in the difference list and find its position from the start of the original strings, used in diff. More...
 
const TListCDiffList::GetList (void) const
 Get list of the diff operations as list<>. More...
 
void CDiffList::Clear (void)
 Remove all elements from the list. More...
 
void CDiffList::Prepend (CDiffOperation::EType operation, CTempString str)
 Add element to the front of the list. More...
 
void CDiffList::Prepend (const CDiffOperation &op)
 Add element to the front of the list. More...
 
void CDiffList::Append (CDiffOperation::EType operation, CTempString str)
 Add element to the end of the list. More...
 
void CDiffList::Append (const CDiffOperation &op)
 Add element to the end of the list. More...
 
void CDiffList::x_CleanupAndMerge_Equities (void)
 Merge adjacent parts with the same operation. More...
 
bool CDiffList::x_CleanupAndMerge_SingleEdits (void)
 Look for single edits surrounded on both sides by equalities which can be shifted sideways to eliminate an equality. More...
 
void CDiffBase::SetTimeout (const CTimeout &tmo)
 Set timeout. More...
 
bool CDiffBase::IsTimeoutExpired () const
 Check if timeout is expired. More...
 
 CDiffBase::CDiffBase (void)
 Constructor. More...
 
void CDiffBase::Reset (void)
 Reset internal state and prepare to next Diff() More...
 
CDiffListCDiff::Diff (CTempString s1, CTempString s2, TFlags flags=0)
 Find the differences between two texts (character mode). More...
 
bool CDiff::x_DiffHalfMatch (CTempString s1, CTempString s2, TDiffHalfMatchList &hm) const
 Do the two texts share a substring which is at least half the length of the longer text? This speedup can produce non-minimal diffs. More...
 
bool CDiff::x_DiffHalfMatchI (CTempString long_str, CTempString short_str, size_type i, TDiffHalfMatchList &hm) const
 Does a substring of short string exist within long string such that the substring is at least half the length of long string? More...
 
void CDiff::x_DiffBisect (CTempString s1, CTempString s2, CDiffList &diffs) const
 Find the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff. More...
 
void CDiff::x_DiffBisectSplit (CTempString s1, CTempString s2, int x, int y, CDiffList &diffs) const
 Given the location of the 'middle snake', split the diff in two parts and recurse. More...
 
void CDiff::x_Diff (CTempString s1, CTempString s2, CDiffList &diffs) const
 Find the differences between two texts. More...
 
CDiffListCDiffText::Diff (CTempString text1, CTempString text2, TFlags flags=0)
 Find the differences between two texts (line mode). More...
 
CNcbiOstreamCDiffText::PrintUnifiedDiff (CNcbiOstream &out, CTempString text1, CTempString text2, unsigned int num_common_lines=3)
 Find the differences between two texts and print result into output stream in unified-like format. More...
 
virtual const char * CDiffException::GetErrCodeString (void) const override
 Get error code interpreted as text. More...
 
 CDiffException::NCBI_EXCEPTION_DEFAULT (CDiffException, CException)
 

Variables

size_type CDiffOperation::SPos::first
 Position in first (original) string. More...
 
size_type CDiffOperation::SPos::second
 Position in second (result) string. More...
 
EType CDiffOperation::m_Operation
 Type of the current diff operation. More...
 
CTempString CDiffOperation::m_String
 The string associated with this diff operation. More...
 
size_type CDiffOperation::m_Length
 The real length of the m_String (including EOL, if it was truncated in line-mode diff) More...
 
SPos CDiffOperation::m_Offset
 The offsets of the current string in the original string (or NPOS) More...
 
SPos CDiffOperation::m_Line
 Line numbers of the current diff (or NPOS) – line-mode only. More...
 
TList CDiffList::m_List
 List of the differences. More...
 
CDiffList CDiffBase::m_Diffs
 The list of differences from the last diff. More...
 
CTimeout CDiffBase::m_Timeout
 Relative timeout for processing. More...
 
CDeadlineCDiffBase::m_Deadline
 Deadline for processing (NULL if not set) More...
 

Friends

class CDiffOperation::CDiffList
 
class CDiffOperation::CDiff
 
class CDiffOperation::CDiffText
 
class CDiffList::CDiff
 
class CDiffList::CDiffText
 
class CDiffBase::CDiff
 
class CDiffBase::CDiffText
 

Detailed Description

Typedef Documentation

◆ size_type [1/3]

typedef size_t CDiffOperation::size_type

Definition at line 69 of file diff.hpp.

◆ size_type [2/3]

Size type definition.

Definition at line 188 of file diff.hpp.

◆ size_type [3/3]

Type definition.

Definition at line 292 of file diff.hpp.

◆ TDiffHalfMatchList

typedef vector<CTempString> CDiff::TDiffHalfMatchList
private

Five element array for the list of strings, returned by x_DiffHalfMatch()

Definition at line 363 of file diff.hpp.

◆ TFlags [1/2]

typedef unsigned int CDiff::TFlags

Bitwise OR of "EFlags".

Definition at line 346 of file diff.hpp.

◆ TFlags [2/2]

typedef unsigned int CDiffText::TFlags

Bitwise OR of "Flags".

Definition at line 407 of file diff.hpp.

◆ TList

Storage class type for the list of diff operations.

Definition at line 190 of file diff.hpp.

Enumeration Type Documentation

◆ EErrCode

Enumerator
eEmpty 
eBadFlags 

Definition at line 475 of file diff.hpp.

◆ EFlags [1/2]

Processing flags.

Enumerator
fNoCleanup 

By default Diff() automatically call CleanupAndMerge() for the generated list of differences to have a shorter and cleaner list of results.

It is on by default for regular character-based diff. But if you need faster (and less optimal) result, you can skip it.

fCalculateOffsets 

Automatically call CalculateOffests() for the generated list of differences.

Definition at line 336 of file diff.hpp.

◆ EFlags [2/2]

Processing flags.

Enumerator
fCleanup 

Automatically call CleanupAndMerge() for the generated list of differences after Diff() to have a shorter and cleaner list of results.

It is off by default for line-based diffs.

fCalculateOffsets 

Automatically call CalculateOffests() for the generated list of differences.

fIgnoreEOL 

Ignore differences in end-of-line types on string comparison.

fRemoveEOL 

Remove end-of-line symbols from each string added to the list, which can be obtained using CDiffOperation::GetString().

This flag is incompatible with fCleanup, exception will be thrown if they where used together. The fRemoveEOL affect a visual appearance of the string, and do not have an influence on how lines with different kind of EOLs compares, use fIgnoreEOL in addition if necessary.

Definition at line 388 of file diff.hpp.

◆ EType

enum CDiffOperation::EType ( void  )

Type of the current diff operation.

Enumerator
eDelete 

String that exists in old text, and deleted in new one.

eEqual 

String exists in both texts.

eInsert 

String that exists in new text, and deleted in old one.

Definition at line 72 of file diff.hpp.

Function Documentation

◆ Append() [1/2]

void CDiffList::Append ( CDiffOperation::EType  operation,
CTempString  str 
)
inline

Add element to the end of the list.

Definition at line 578 of file diff.hpp.

References CDiffList::m_List, and str().

Referenced by CDiff::Diff(), CDiffText::Diff(), CDiff::x_Diff(), and CDiff::x_DiffBisect().

◆ Append() [2/2]

void CDiffList::Append ( const CDiffOperation op)
inline

Add element to the end of the list.

Definition at line 586 of file diff.hpp.

References CDiffList::m_List.

◆ CalculateOffsets()

void CDiffList::CalculateOffsets ( void  )

Calculate offsets for all substrings in the difference list and find its position from the start of the original strings, used in diff.

For performance reasons, Diff() do not operate with offsets of the substrings and do not store them, but as original strings can be easy reconstructed from the list of diffs, that offsets also can be calculated afterwards.

For DELETE or EQUAl type operations the calculated value is an offset of the substring in the first (original) string used in diff. For INSERT type operation the calculated value is an offset in the second (result) string used in diff.

Note
This method cannot calculate rows and columns for regular diffs, use line-mode diffs that do this automatically.
See also
CDiffOperation::GetOffset()

Definition at line 152 of file diff.cpp.

References DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, eEmpty, CDiffList::m_List, NCBI_THROW, NON_CONST_ITERATE, and NPOS.

Referenced by CDiff::Diff(), and CDiffText::Diff().

◆ CDiffBase()

CDiffBase::CDiffBase ( void  )
inlineprivate

Constructor.

Definition at line 308 of file diff.hpp.

◆ CDiffList()

CDiffList::CDiffList ( void  )
inline

Constructor.

Definition at line 193 of file diff.hpp.

◆ CDiffOperation()

CDiffOperation::CDiffOperation ( EType  operation,
CTempString  str 
)

Constructor.

Parameters
operationType of the current diff operation.
strThe string associated with this diff operation.

Definition at line 58 of file diff.cpp.

◆ CleanupAndMerge()

void CDiffList::CleanupAndMerge ( void  )

Reorder and merge like edit sections, merge equalities.

This method can make resulting list cleaner and shorter, but this can take some time.

Definition at line 125 of file diff.cpp.

References ITERATE, CDiffList::m_List, NCBI_THROW, CDiffList::x_CleanupAndMerge_Equities(), and CDiffList::x_CleanupAndMerge_SingleEdits().

Referenced by CDiff::Diff(), and CDiffText::Diff().

◆ Clear()

void CDiffList::Clear ( void  )
inline

Remove all elements from the list.

Definition at line 592 of file diff.hpp.

References CDiffList::m_List.

Referenced by CDiffBase::Reset().

◆ Diff() [1/2]

CDiffList & CDiff::Diff ( CTempString  s1,
CTempString  s2,
TFlags  flags = 0 
)

Find the differences between two texts (character mode).

Parameters
s1Old string to be diffed.
s2New string to be diffed. @flags Processing flags.
Returns
The list of operations that should be done to convert string 's1' to 's2'.
See also
SetTimeout(), CDiffText

Definition at line 364 of file diff.cpp.

References CDiffList::Append(), CDiffList::CalculateOffsets(), CDiffList::CleanupAndMerge(), NStr::CommonPrefixSize(), NStr::CommonSuffixSize(), DIFF_EQUAL, CTempString::empty(), F_ISSET, CDiff::fCalculateOffsets, CDiff::fNoCleanup, CTimeout::IsInfinite(), CDiffBase::IsTimeoutExpired(), CTempString::length(), CDiffBase::m_Deadline, CDiffBase::m_Diffs, CDiffBase::m_Timeout, NULL, CDiffList::Prepend(), CDiff_Base::Reset(), CTempString::substr(), and CDiff::x_Diff().

◆ Diff() [2/2]

CDiffList & CDiffText::Diff ( CTempString  text1,
CTempString  text2,
TFlags  flags = 0 
)

Find the differences between two texts (line mode).

Run a line-based diff, that operates with whole lines, and not trying to find a differences inside added/deleted blocks of lines.

Parameters
text1Old text to be diffed.
text2New text to be diffed. @flags Processing flags. Default: non-optimal line-based diff that have all EOLs.
Returns
The list of operations that should be done to convert text 's1' to 's2'.
See also
SetTimeout(), CDiff

Definition at line 766 of file diff.cpp.

References _TROUBLE, _VERIFY, CDiffList::Append(), CDiffList::CalculateOffsets(), CDiffList::CleanupAndMerge(), dtl::Diff< elem, sequence, comparator >::compose(), CTempString::data(), DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, F_ISSET, CDiffText::fCalculateOffsets, CDiffText::fCleanup, CDiffText::fIgnoreEOL, CDiffText::fRemoveEOL, dtl::Diff< elem, sequence, comparator >::getSes(), i, CTimeout::IsInfinite(), CDiffBase::IsTimeoutExpired(), len, CTempString::length(), line1, line2, CDiffBase::m_Deadline, CDiffBase::m_Diffs, CDiffList::m_List, CDiffBase::m_Timeout, NCBI_THROW, NPOS, NULL, dtl::Diff< elem, sequence, comparator >::onHuge(), CDiffBase::Reset(), dtl::SES_ADD, dtl::SES_COMMON, dtl::SES_DELETE, CDiffOperation::SetLength(), CDiffOperation::SetLine(), NStr::Split(), and str().

Referenced by CDiffText::PrintUnifiedDiff().

◆ GetEditDistance()

CDiffList::size_type CDiffList::GetEditDistance ( void  ) const

Compute the edit distance (Levenshtein distance).

Can be used to check how much strings differ.

Returns
Return number of single-character edits in the current difference list, including the number of inserted, deleted or substituted characters, required to be done to convert one string to another. Return zero if diffed strings are equal.

Definition at line 70 of file diff.cpp.

References DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, eEmpty, CDiffList::GetList(), ITERATE, max(), and NCBI_THROW.

◆ GetErrCodeString()

const char * CDiffException::GetErrCodeString ( void  ) const
overridevirtual

Get error code interpreted as text.

Reimplemented from CException.

Definition at line 1164 of file diff.cpp.

References CDiffException::eBadFlags, CDiffException::eEmpty, CException::GetErrCode(), and CException::GetErrCodeString().

◆ GetLength()

size_type CDiffOperation::GetLength ( void  ) const
inline

Get string length.

For character-based diffs it is the same as GetString().length(). But in the line-based diffs the string can be truncated and it may not have ending EOL. So, the original string can be reconstructed using: CTempString(op.GetString().data(), op.GetLength())

Definition at line 113 of file diff.hpp.

References CDiffOperation::m_Length.

◆ GetLine()

CDiffOperation::SPos CDiffOperation::GetLine ( void  ) const
inline

Get line number of the current difference (line-mode diff only).

Line numbers are 1-based.

Returns
  • 1-based line number of the current difference in line-mode only. Always return NPOS in block-mode.
  • GetLine().first returns line number for DELETE and EQUAL operations only, GetLine().second for INSERT and EQUAL only.
  • NPOS otherwise.
See also
GetOperation(), GetString(), GetOffset(), CDiff::DiffLines()

Definition at line 516 of file diff.hpp.

References CDiffOperation::m_Line.

◆ GetList()

const CDiffList::TList & CDiffList::GetList ( void  ) const
inline

Get list of the diff operations as list<>.

Definition at line 558 of file diff.hpp.

References CDiffList::m_List.

Referenced by CDiffList::GetEditDistance(), CDiffList::GetLongestCommonSubstring(), and CDiffText::PrintUnifiedDiff().

◆ GetLongestCommonSubstring()

CTempString CDiffList::GetLongestCommonSubstring ( void  ) const

Find the longest common substring for current difference list.

Returns
The algorithm just returns the first longest common substring it finds, which therefore may not be unique. Return empty string if compared strings where fully different and no common substrings where found.
Note
If current difference list is not optimal, the result can be shorter than it should be. Use CleanupAndMerge() first to get more optimized diff.
For not optimized line-based diffs it return a first longest common line.

Definition at line 101 of file diff.cpp.

References eEmpty, CDiffList::GetList(), ITERATE, len, and NCBI_THROW.

◆ GetOffset()

CDiffOperation::SPos CDiffOperation::GetOffset ( void  ) const
inline

Get offset of the current difference in the original text.

Return structure with offsets in the first (original) and in the second (result) strings.

For performance reasons, Diff() does not operate with offsets of the substrings and it does not store them. Original strings can be easily reconstructed from the list of diffs, and offsets also can be calculated afterwards. See CDiffList::CalculateOffsets().

Returns
  • Zero-based offset of the current difference in the original text. The offset is counting from the start of the text for both block- and line-based modes.
  • NPOS if offset is not calculated or unknown.
  • GetOffset().first represents offsets for DELETE and EQUAL operation only, GetOffset().second for INSERT and EQUAL only.
See also
GetOperation(), GetString(), GetLine(), CDiff::Diff(), CDiffList::CalculateOffsets()

Definition at line 510 of file diff.hpp.

References CDiffOperation::m_Offset.

◆ GetOperation()

EType CDiffOperation::GetOperation ( void  ) const
inline

Get type of operation.

Definition at line 95 of file diff.hpp.

References CDiffOperation::m_Operation.

◆ GetString()

CTempString CDiffOperation::GetString ( void  ) const
inline

Get string for current operation.

Definition at line 103 of file diff.hpp.

References CDiffOperation::m_String.

◆ IsDelete()

bool CDiffOperation::IsDelete ( void  ) const
inline

Definition at line 99 of file diff.hpp.

References CDiffOperation::eDelete, and CDiffOperation::m_Operation.

◆ IsEqual()

bool CDiffOperation::IsEqual ( void  ) const
inline

Definition at line 100 of file diff.hpp.

References CDiffOperation::eEqual, and CDiffOperation::m_Operation.

◆ IsInsert()

bool CDiffOperation::IsInsert ( void  ) const
inline

Check type of operation.

Definition at line 98 of file diff.hpp.

References CDiffOperation::eInsert, and CDiffOperation::m_Operation.

◆ IsTimeoutExpired()

bool CDiffBase::IsTimeoutExpired ( ) const
inline

Check if timeout is expired.

Definition at line 610 of file diff.hpp.

References CDeadline::IsExpired(), and CDiffBase::m_Deadline.

Referenced by CDiff::Diff(), CDiffText::Diff(), and CDiff::x_DiffBisect().

◆ NCBI_EXCEPTION_DEFAULT()

CDiffException::NCBI_EXCEPTION_DEFAULT ( CDiffException  ,
CException   
)

◆ operator!=()

bool CDiffOperation::operator!= ( const CDiffOperation diff_op) const
inline

Definition at line 504 of file diff.hpp.

References CDiffOperation::operator==().

◆ operator==()

bool CDiffOperation::operator== ( const CDiffOperation diff_op) const
inline

Compare substrings and operation types only, all other attributes (offset, row, col and etc) are not used in comparison.

Definition at line 497 of file diff.hpp.

References CDiffOperation::m_Operation, and CDiffOperation::m_String.

Referenced by CDiffOperation::operator!=().

◆ Prepend() [1/2]

void CDiffList::Prepend ( CDiffOperation::EType  operation,
CTempString  str 
)
inline

Add element to the front of the list.

Definition at line 564 of file diff.hpp.

References CDiffList::m_List, and str().

Referenced by CDiff::Diff(), and CDiffList::x_CleanupAndMerge_Equities().

◆ Prepend() [2/2]

void CDiffList::Prepend ( const CDiffOperation op)
inline

Add element to the front of the list.

Definition at line 572 of file diff.hpp.

References CDiffList::m_List.

◆ PrintUnifiedDiff()

CNcbiOstream & CDiffText::PrintUnifiedDiff ( CNcbiOstream out,
CTempString  text1,
CTempString  text2,
unsigned int  num_common_lines = 3 
)

Find the differences between two texts and print result into output stream in unified-like format.

Parameters
outThe output stream.
text1Old text to be diffed.
text2New text to be diffed.
num_common_linesThe number of unchanged lines shown above and below a change hunk. Three lines is typically the default. Use zero, if you need to see a changes only, without any surrounding text.
See also
Diff()
Note
Using CTempStrings internally is faster and use less memory, but do not allow to perform some optimizations and cleanup, so result can looks different that 'diff' utility provide, and have more hunks. Also, the printed result have next differences from canonical unified format: 1) Unified format allow crossed hunks, when end of the first and start of the second hunk have the same unchanged lines of text. This version don't have crossed hunks. If some hunks crosses, the second will be started with less number of unchanged lines that specified by 'num_common_lines' parameter. 2) Unified format can have zero-based line numbers. like: @ -0,0 +1,1 @ +Added line. This version always use one-based line numbers: @ -1,0 +1,1 @ +Added line.
It is not fully compatible with result provided by 'diff -u' (or -U NNN), and sometimes it is impossible to use 'patch' utility with provided diff.

Definition at line 1048 of file diff.cpp.

References CDiffText::Diff(), DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, CDiffText::fRemoveEOL, CDiffList::GetList(), out(), and s_PrintUnifiedHunk().

◆ Reset()

void CDiffBase::Reset ( void  )
inlineprotected

Reset internal state and prepare to next Diff()

Definition at line 603 of file diff.hpp.

References CDiffList::Clear(), CDiffBase::m_Deadline, CDiffBase::m_Diffs, and NULL.

Referenced by CDiffText::Diff().

◆ SetLength()

void CDiffOperation::SetLength ( size_type  length)
inlineprotected

Definition at line 528 of file diff.hpp.

References CDiffOperation::m_Length.

Referenced by CDiffText::Diff().

◆ SetLine()

void CDiffOperation::SetLine ( SPos  line)
inlineprotected

Definition at line 547 of file diff.hpp.

References CDiffOperation::m_Line.

Referenced by CDiffText::Diff().

◆ SetOffset()

void CDiffOperation::SetOffset ( SPos  offset)
inlineprotected

Definition at line 541 of file diff.hpp.

References CDiffOperation::m_Offset, and offset.

◆ SetOperation()

void CDiffOperation::SetOperation ( EType  operation)
inlineprotected

Definition at line 522 of file diff.hpp.

References CDiffOperation::m_Operation.

◆ SetString()

void CDiffOperation::SetString ( CTempString  str,
size_type  len = NPOS 
)
inlineprotected

Definition at line 534 of file diff.hpp.

References len, CDiffOperation::m_Length, CDiffOperation::m_String, NPOS, and str().

◆ SetTimeout()

void CDiffBase::SetTimeout ( const CTimeout tmo)
inline

Set timeout.

Despite the large number of optimizations used in Diff(), it can take a while to compute. You can limit its execution time using this method. The default value for timeout if not specified is infinity, that lets diff run until completion. Should diff timeout, the return value will still be a valid difference, though probably non-optimal.

Definition at line 301 of file diff.hpp.

References CDiffBase::m_Timeout.

◆ SPos()

CDiffOperation::SPos::SPos ( size_type  p1 = NPOS,
size_type  p2 = NPOS 
)
inline

Definition at line 82 of file diff.hpp.

◆ x_CleanupAndMerge_Equities()

void CDiffList::x_CleanupAndMerge_Equities ( void  )
private

Merge adjacent parts with the same operation.

Any edit section can move as long as it doesn't cross an equality.

Definition at line 182 of file diff.cpp.

References NStr::CommonPrefixSize(), NStr::CommonSuffixSize(), CTempString::data(), DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, CTempString::length(), CDiffList::m_List, CDiffList::Prepend(), and CTempString::substr().

Referenced by CDiffList::CleanupAndMerge().

◆ x_CleanupAndMerge_SingleEdits()

bool CDiffList::x_CleanupAndMerge_SingleEdits ( void  )
private

Look for single edits surrounded on both sides by equalities which can be shifted sideways to eliminate an equality.

e.g: ABAC -> ABAC Return TRUE if shifts were made and the diff needs reordering and another shift sweep

Definition at line 287 of file diff.cpp.

References _VERIFY, CTempString::data(), DIFF_EQUAL, NStr::EndsWith(), CTempString::length(), CDiffList::m_List, and NStr::StartsWith().

Referenced by CDiffList::CleanupAndMerge().

◆ x_Diff()

void CDiff::x_Diff ( CTempString  s1,
CTempString  s2,
CDiffList diffs 
) const
private

Find the differences between two texts.

Assumes that the texts do not have any common prefix or suffix.

Parameters
s1Old string to be diffed.
s2New string to be diffed.
diffsResulting list of the diff operations.
See also
Diff

Definition at line 705 of file diff.cpp.

References CDiffList::Append(), DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, CTempString::empty(), CTempString::find(), i, CTempString::length(), CDiffList::m_List, NPOS, CTempString::substr(), CDiff::x_DiffBisect(), and CDiff::x_DiffHalfMatch().

Referenced by CDiff::Diff(), and CDiff::x_DiffBisectSplit().

◆ x_DiffBisect()

void CDiff::x_DiffBisect ( CTempString  s1,
CTempString  s2,
CDiffList diffs 
) const
private

Find the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff.

See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.

Parameters
s1Old string to be diffed.
s2New string to be diffed.
diffsResulting list of the diff operations.
See also
Diff

Definition at line 551 of file diff.cpp.

References CDiffList::Append(), delta(), DIFF_DELETE, DIFF_INSERT, ctll::front(), int, CDiffBase::IsTimeoutExpired(), CTempString::length(), v2, and CDiff::x_DiffBisectSplit().

Referenced by CDiff::x_Diff().

◆ x_DiffBisectSplit()

void CDiff::x_DiffBisectSplit ( CTempString  s1,
CTempString  s2,
int  x,
int  y,
CDiffList diffs 
) const
private

Given the location of the 'middle snake', split the diff in two parts and recurse.

Parameters
s1Old string to be diffed.
s2New string to be diffed.
xIndex of split point in 's1'.
yIndex of split point in 's2'.
diffsResulting list of the diff operations.
See also
Diff, x_DiffBisect

Definition at line 683 of file diff.cpp.

References CTempString::substr(), and CDiff::x_Diff().

Referenced by CDiff::x_DiffBisect().

◆ x_DiffHalfMatch()

bool CDiff::x_DiffHalfMatch ( CTempString  s1,
CTempString  s2,
TDiffHalfMatchList hm 
) const
private

Do the two texts share a substring which is at least half the length of the longer text? This speedup can produce non-minimal diffs.

Parameters
s1First string.
s2Second string.
hmFive element array, containing the prefix of 's1', the suffix of 's1', the prefix of 's2', the suffix of 's2' and the common middle.
Returns
FALSE if there was no match.
See also
Diff

Definition at line 442 of file diff.cpp.

References CTimeout::IsInfinite(), CTempString::length(), CDiffBase::m_Timeout, tmp, and CDiff::x_DiffHalfMatchI().

Referenced by CDiff::x_Diff().

◆ x_DiffHalfMatchI()

bool CDiff::x_DiffHalfMatchI ( CTempString  long_str,
CTempString  short_str,
size_type  i,
TDiffHalfMatchList hm 
) const
private

Does a substring of short string exist within long string such that the substring is at least half the length of long string?

Parameters
long_strLonger string.
short_strShorter string.
iStart index of quarter length substring within long string.
hmFive element Array, containing the prefix of 'long_str', the suffix of 'long_str', the prefix of 'short_str', the suffix of 'short_str' and the common middle.
Returns
FALSE if there was no match.
See also
Diff, x_DiffHalfMatch

Definition at line 505 of file diff.cpp.

References NStr::CommonPrefixSize(), NStr::CommonSuffixSize(), CTempString::find(), i, CTempString::length(), NPOS, seed, and CTempString::substr().

Referenced by CDiff::x_DiffHalfMatch().

Variable Documentation

◆ first

size_type CDiffOperation::SPos::first

Position in first (original) string.

Definition at line 80 of file diff.hpp.

◆ m_Deadline

CDeadline* CDiffBase::m_Deadline
protected

Deadline for processing (NULL if not set)

Definition at line 319 of file diff.hpp.

Referenced by CDiff::Diff(), CDiffText::Diff(), CDiffBase::IsTimeoutExpired(), and CDiffBase::Reset().

◆ m_Diffs

CDiffList CDiffBase::m_Diffs
protected

The list of differences from the last diff.

Definition at line 317 of file diff.hpp.

Referenced by CDiff::Diff(), CDiffText::Diff(), and CDiffBase::Reset().

◆ m_Length

size_type CDiffOperation::m_Length
private

The real length of the m_String (including EOL, if it was truncated in line-mode diff)

Definition at line 170 of file diff.hpp.

Referenced by CDiffOperation::GetLength(), CDiffOperation::SetLength(), and CDiffOperation::SetString().

◆ m_Line

SPos CDiffOperation::m_Line
private

Line numbers of the current diff (or NPOS) – line-mode only.

Definition at line 173 of file diff.hpp.

Referenced by CDiffOperation::GetLine(), and CDiffOperation::SetLine().

◆ m_List

TList CDiffList::m_List
private

◆ m_Offset

SPos CDiffOperation::m_Offset
private

The offsets of the current string in the original string (or NPOS)

Definition at line 172 of file diff.hpp.

Referenced by CDiffOperation::GetOffset(), and CDiffOperation::SetOffset().

◆ m_Operation

EType CDiffOperation::m_Operation
private

◆ m_String

CTempString CDiffOperation::m_String
private

The string associated with this diff operation.

Definition at line 169 of file diff.hpp.

Referenced by CDiffOperation::GetString(), CDiffOperation::operator==(), and CDiffOperation::SetString().

◆ m_Timeout

CTimeout CDiffBase::m_Timeout
protected

Relative timeout for processing.

Definition at line 318 of file diff.hpp.

Referenced by CDiff::Diff(), CDiffText::Diff(), CDiffBase::SetTimeout(), and CDiff::x_DiffHalfMatch().

◆ second

size_type CDiffOperation::SPos::second

Position in second (result) string.

Definition at line 81 of file diff.hpp.

Friends

◆ CDiff [1/3]

friend class CDiff
friend

Definition at line 164 of file diff.hpp.

◆ CDiff [2/3]

friend class CDiff
friend

Definition at line 277 of file diff.hpp.

◆ CDiff [3/3]

friend class CDiff ( void  )
friend

Definition at line 321 of file diff.hpp.

◆ CDiffList

friend class CDiffList
friend

Definition at line 163 of file diff.hpp.

◆ CDiffText [1/3]

friend class CDiffText
friend

Definition at line 165 of file diff.hpp.

◆ CDiffText [2/3]

friend class CDiffText
friend

Definition at line 278 of file diff.hpp.

◆ CDiffText [3/3]

friend class CDiffText
friend

Definition at line 322 of file diff.hpp.

Modified on Wed Sep 04 15:01:14 2024 by modify_doxy.py rev. 669887