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 apply_loop_acc() :: {[boolean()], String.t(), integer(), options()}
@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

Link to this function

add_context(patch, text, patch_margin, match_max_bits \\ 32)

View Source
@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 - The Patch 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.

Link to this function

add_diff_to_subpatch(first_diff, rest, patch, acc)

View Source
Link to this function

add_other_diff_to_subpatch(arg1, rest, patch, arg2)

View Source
Link to this function

add_padding(patches, patch_margin)

View Source
@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.

Link to this function

apply(patches, text, opts \\ [])

View Source
@spec apply(patchlist(), String.t(), options()) :: {String.t(), [boolean()]}
Link to this function

apply_match_diff(arg, acc_text, index1, diffs, start_loc)

View Source
Link to this function

bad_match?(diffs, text1, opts)

View Source
Link to this function

from_diffs(diffs, opts \\ [])

View Source
@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 from text1 to text2.
  • opts - A options keyword list, [] to use the default options.

Returns a patchlist.

@spec from_text(String.t()) :: patchlist()

Parse a textual representation of patches and return a patchlist.

Raises an ArgumentError if the text has invalid contents.

Link to this function

from_texts_and_diffs(text1, text2, diffs, opts \\ [])

View Source
@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 from text1 to text2.
  • 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 String text2, a difflist that turns text1 into text2 will be computed.
  • If b is a difflist, it is the delta between text1 and the target text2.
  • opts - A options keyword list, [] to use the default options.

Returns a patchlist.

Link to this function

split_max(patches, patch_margin, match_max_bits \\ 32)

View Source
@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.

Link to this function

subpatch_loop(bigpatch_diffs, patch, acc)

View Source

Return the textual representation of a patchlist.