pub struct DiffMatchPatch {
    pub diff_timeout: Option<Duration>,
    pub edit_cost: i32,
    pub match_distance: i32,
    pub patch_margin: i32,
    pub match_maxbits: i32,
    pub match_threshold: f32,
    pub patch_delete_threshold: f32,
}
Expand description

Diff Match and Patch methods

Fields§

§diff_timeout: Option<Duration>

Time duration to map a diff before giving up (None for infinity).

§edit_cost: i32

Cost of an empty edit operation in terms of edit characters.

§match_distance: i32

How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).*/

§patch_margin: i32

Chunk size for context length.

§match_maxbits: i32

The number of bits in an int.

§match_threshold: f32

At what point is no match declared (0.0 = perfection, 1.0 = very loose).

§patch_delete_threshold: f32

Implementations§

source§

impl DiffMatchPatch

source

pub fn match_main( &mut self, text: &[char], pattern: &[char], loc: usize ) -> Option<usize>

Locate the best instance of ‘pattern’ in ‘text’ near ‘loc’.

Args: text: The text to search. pattern: The pattern to search for. loc: The location to search around.

Returns: Best match index or -1.

source

pub fn match_bitap( &mut self, text: &[char], patern: &[char], loc: usize ) -> Option<usize>

Locate the best instance of ‘pattern’ in ‘text’ near ‘loc’ using the Bitap algorithm.

Args: text: The text to search. pattern: The pattern to search for. loc: The location to search around.

Returns: Best match index or -1.

source

pub fn match_alphabet(&mut self, patern: &[char]) -> HashMap<char, i32>

Initialise the alphabet for the Bitap algorithm.

Args: pattern: The text to encode.

Returns: Hash of character locations.

source§

impl DiffMatchPatch

source

pub fn new() -> Self

source

pub fn diff_chars_to_lines(&self, diffs: &mut [Diff], line_array: &[Chars])

Rehydrate the text in a diff from a string of line hashes to real lines of text.

Args: diffs: Vector of diffs as changes. lineArray: Vector of unique strings.

source

pub fn diff_common_prefix(&self, text1: &[char], text2: &[char]) -> usize

Determine the common prefix of two strings.

Args: text1: First strings. text2: Second strings.

Returns: The number of characters common to the start of each chars.

source

pub fn diff_common_suffix(&self, text1: &[char], text2: &[char]) -> usize

Determine the common suffix of two strings.

Args: text1: First chars. text2: Second chars.

Returns: The number of characters common to the end of each chars.

source

pub fn diff_common_overlap(&self, text1: &[char], text2: &[char]) -> usize

source

pub fn diff_half_match<'a>( &self, text1: &'a [char], text2: &'a [char] ) -> Option<Vec<&'a [char]>>

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.

Args: text1: First chars. text2: Second chars.

Returns: Five element Vector, containing the prefix of text1, the suffix of text1, the prefix of text2, the suffix of text2 and the common middle. Or empty vector if there was no match.

source

pub fn diff_chars_to_any<T>( &self, diffs: &[Diff], item_array: &[T] ) -> Vec<Diff<Vec<T>>> where T: Clone,

Recover compressed chars to array of any type

source

pub fn diff_any_to_chars<T>( &self, seq1: &[T], seq2: &[T] ) -> (Chars, Chars, Vec<T>)where T: Hash + Eq + Clone + Default,

Reduce the sequences to a string

source

pub fn diff_lines_to_chars( &self, text1: &[char], text2: &[char] ) -> (Chars, Chars, Vec<Chars>)

Split two texts into an array of strings. Reduce the texts to a string of hashes where each Unicode character represents one line.

Args: text1: First chars. text2: Second chars.

Returns: Three element tuple, containing the encoded text1, the encoded text2 and the array of unique strings. The zeroth element of the array of unique strings is intentionally blank.

source

pub fn diff_cleanup_merge(&self, diffs: &mut Vec<Diff>)

Reorder and merge like edit sections. Merge equalities. Any edit section can move as long as it doesn’t cross an equality.

Args: diffs: vectors of diff object.

source

pub fn diff_cleanup_semantic_lossless(&self, diffs: &mut Vec<Diff>)

Look for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary. e.g: The cat came. -> The cat came.

Args: diffs: Vector of diff object.

source

pub fn diff_cleanup_semantic(&self, diffs: &mut Vec<Diff>)

Reduce the number of edits by eliminating semantically trivial equalities.

Args: diffs: Vectors of diff object.

source

pub fn diff_cleanup_efficiency(&self, diffs: &mut Vec<Diff>)

Reduce the number of edits by eliminating operationally trivial equalities.

Args: diffs: Vector of diff object.

source

pub fn diff_text1(&self, diffs: &[Diff]) -> Chars

Compute and return the source text (all equalities and deletions).

Args: diffs: Vectoe of diff object.

Returns: Source text.

source

pub fn diff_text2(&self, diffs: &[Diff]) -> Chars

Compute and return the destination text (all equalities and insertions).

Args: diffs: Vector of diff object.

Returns: destination text.

source

pub fn diff_xindex(&self, diffs: &[Diff], loc: usize) -> usize

loc is a location in text1, compute and return the equivalent location in text2. e.g. “The cat” vs “The big cat”, 1->1, 5->8

Args: diffs: Vector of diff object. loc: Location within text1.

Returns: Location within text2.

source

pub fn diff_levenshtein(&self, diffs: &[Diff]) -> usize

source

pub fn diff_to_delta(&self, diffs: &[Diff]) -> String

source

pub fn diff_from_delta(&self, _text1: &mut Chars, _delta: &str)

source

pub fn diff_to_html(&self, diffs: &[Diff]) -> String

source

pub fn diff_bisect(&mut self, text1: &[char], text2: &[char]) -> Vec<Diff>

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.

Args: text1: Old chars to be diffed. text2: New chars to be diffed.

Returns: Vector of diffs as changes.

source

pub fn diff_main( &self, text1: &[char], text2: &[char], checklines: bool ) -> Vec<Diff>

Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.

Args: text1: Old string to be diffed. text2: New string to be diffed. checklines: Optional speedup flag. If present and false, then don’t run a line-level diff first to identify the changed areas. Defaults to true, which does a faster, slightly less optimal diff. Returns: Vector of diffs as changes.

source

pub fn diff_linemode(&mut self, text1: &[char], text2: &[char]) -> Vec<Diff>

Do a quick line-level diff on both chars, then rediff the parts for greater accuracy. This speedup can produce non-minimal diffs.

Args: text1: Old chars to be diffed. text2: New chars to be diffed.

Returns: Vector of diffs as changes.

Trait Implementations§

source§

impl Default for DiffMatchPatch

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.