View Source Dmp.Patch (diff_match_patch v0.2.0)
Apply a list of patches onto plain text. Use best effort to apply patch even when the underlying text doesn't match.
Link to this section Summary
Functions
Increase the context until it is unique, but don't let the pattern expand beyond match_max_bits.
Add some padding on text start and end so that edges can match something.
Merge a set of patches onto the text. Return a patched text, as well as an array of true/false values indicating which patches were applied.
Compute a list of patches to turn text1
into text2
. text1
will be derived
from the provided diffs.
Parse a textual representation of patches and return a patchlist.
This function can be called two ways. In either case the first argument,
a
is the original text (text1
).
Look through the patches and break up any which are longer than the maximum limit of the match algorithm.
Return the textual representation of a patchlist.
Link to this section Types
@type options() :: Dmp.Options.t()
@type patchlist() :: [t()]
@type t() :: %Dmp.Patch{ diffs: Dmp.Diff.difflist(), length1: non_neg_integer(), length2: non_neg_integer(), start1: non_neg_integer(), start2: non_neg_integer() }
Link to this section Functions
@spec add_context(t(), String.t(), non_neg_integer(), non_neg_integer()) :: t()
Increase the context until it is unique, but don't let the pattern expand beyond match_max_bits.
patch
- ThePatch
to grow.text
- Source text.patch_margin
- Chunk size for context length.match_max_bits
- The number of bits in an integer (default is expected 32).
Returns the updated Patch
.
@spec add_padding(patchlist(), non_neg_integer()) :: {patchlist(), String.t()}
Add some padding on text start and end so that edges can match something.
Intended to be called only from within Patch.apply
.
patches
- A patchlist..patch_margin
- Chunk size for context length.
Returns a tuple of the padded patchlist and the padding string added to each side.
Merge a set of patches onto the text. Return a patched text, as well as an array of true/false values indicating which patches were applied.
patches
- A patchlist.text
- Text to apply patch to.opts
- A options keyword list,[]
to use the default options.
Returns a tuple with two elements: the patched text, and a list of
boolean values. Each boolean corresponds to a patch in the patchlist,
and is true
if a match was found for the corresponding patch.
@spec from_diffs(Dmp.Diff.difflist(), options()) :: patchlist()
Compute a list of patches to turn text1
into text2
. text1
will be derived
from the provided diffs.
diffs
- A difflist fromtext1
totext2
.opts
- A options keyword list,[]
to use the default options.
Returns a patchlist.
Parse a textual representation of patches and return a patchlist.
Raises an ArgumentError
if the text has invalid contents.
@spec from_texts_and_diffs(String.t(), String.t(), Dmp.Diff.difflist(), options()) :: patchlist()
Deprecated
Compute a list of patches to turn text1
into text2
. text2
is ignored.
diffs
are the delta between text1 and text2.
text1
- Old text.text2
- Ignored.diffs
- A difflist fromtext1
totext2
.opts
- A options keyword list,[]
to use the default options.
Returns a patchlist.
@spec make(String.t(), String.t() | Dmp.Diff.difflist(), options()) :: patchlist()
This function can be called two ways. In either case the first argument,
a
is the original text (text1
).
The second argument b
has two cases:
- If
b
is a Stringtext2
, a difflist that turnstext1
intotext2
will be computed. - If
b
is a difflist, it is the delta betweentext1
and the targettext2
. opts
- A options keyword list,[]
to use the default options.
Returns a patchlist.
@spec split_max(patchlist(), non_neg_integer(), non_neg_integer()) :: patchlist()
Look through the patches and break up any which are longer than the maximum limit of the match algorithm.
Intended to be called only from within Patch.apply
.
patches
- A patchlist.patch_margin
- Chunk size for context length.match_max_bits
- The number of bits in an int (default 32).
Returns the updated patchlist.
Return the textual representation of a patchlist.