Gin
Loading...
Searching...
No Matches
Classes | Functions
Diff Namespace Reference

Binary diff/patch utilities using the bsdiff algorithm. More...

Classes

struct  Patch
 A compact text patch storing only the differences between two texts. More...
 

Functions

std::vector< uint8_tbsDiff (const juce::String &s1, const juce::String &s2)
 Creates a binary patch that transforms s1 into s2.
 
juce::String bsApplyPatch (const juce::String &s, const std::vector< uint8_t > &patch)
 Applies a binary patch to a string.
 
Patch createPatch (const juce::String &oldText, const juce::String &newText)
 Creates a compact patch that can transform newText back into oldText.
 
juce::String applyPatch (const juce::String &newText, const Patch &patch)
 Applies a patch to transform text back to its original form.
 

Detailed Description

Binary diff/patch utilities using the bsdiff algorithm.

These functions provide efficient binary differencing and patching for strings. The bsdiff algorithm creates compact patches by finding matching sequences between the old and new data.

See also
bsDiff, bsApplyPatch

Function Documentation

◆ bsDiff()

std::vector< uint8_t > Diff::bsDiff ( const juce::String &  s1,
const juce::String &  s2 
)

Creates a binary patch that transforms s1 into s2.

Uses the bsdiff algorithm to generate a compact binary patch representing the differences between two strings. The resulting patch can be applied to s1 using bsApplyPatch() to recreate s2.

Parameters
s1The original string
s2The target string
Returns
A binary patch as a vector of bytes

◆ bsApplyPatch()

juce::String Diff::bsApplyPatch ( const juce::String &  s,
const std::vector< uint8_t > &  patch 
)

Applies a binary patch to a string.

Applies a patch created by bsDiff() to transform the original string into the target string.

Parameters
sThe original string to patch
patchThe binary patch data created by bsDiff()
Returns
The resulting string after applying the patch

◆ createPatch()

Patch Diff::createPatch ( const juce::String &  oldText,
const juce::String &  newText 
)

Creates a compact patch that can transform newText back into oldText.

Uses the Myers diff algorithm to find the minimal differences. Only stores the changes (inserts/removes), not unchanged lines.

Parameters
oldTextThe original text
newTextThe modified text
Returns
A compact Patch containing only the differences

◆ applyPatch()

juce::String Diff::applyPatch ( const juce::String &  newText,
const Patch patch 
)

Applies a patch to transform text back to its original form.

Parameters
newTextThe modified text
patchThe patch created by createPatch()
Returns
The original text