Struct diffmatchpatch::DiffMatchPatch
source · 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
impl DiffMatchPatch
sourcepub fn match_main(
&mut self,
text: &[char],
pattern: &[char],
loc: usize
) -> Option<usize>
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.
sourcepub fn match_bitap(
&mut self,
text: &[char],
patern: &[char],
loc: usize
) -> Option<usize>
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§impl DiffMatchPatch
impl DiffMatchPatch
pub fn new() -> Self
sourcepub fn diff_chars_to_lines(&self, diffs: &mut [Diff], line_array: &[Chars])
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.
sourcepub fn diff_common_prefix(&self, text1: &[char], text2: &[char]) -> usize
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.
sourcepub fn diff_common_suffix(&self, text1: &[char], text2: &[char]) -> usize
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.
pub fn diff_common_overlap(&self, text1: &[char], text2: &[char]) -> usize
sourcepub fn diff_half_match<'a>(
&self,
text1: &'a [char],
text2: &'a [char]
) -> Option<Vec<&'a [char]>>
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.
sourcepub fn diff_chars_to_any<T>(
&self,
diffs: &[Diff],
item_array: &[T]
) -> Vec<Diff<Vec<T>>> ⓘwhere
T: Clone,
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
sourcepub fn diff_any_to_chars<T>(
&self,
seq1: &[T],
seq2: &[T]
) -> (Chars, Chars, Vec<T>)where
T: Hash + Eq + Clone + Default,
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
sourcepub fn diff_lines_to_chars(
&self,
text1: &[char],
text2: &[char]
) -> (Chars, Chars, Vec<Chars>)
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.
sourcepub fn diff_cleanup_merge(&self, diffs: &mut Vec<Diff>)
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.
sourcepub fn diff_cleanup_semantic_lossless(&self, diffs: &mut Vec<Diff>)
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.
sourcepub fn diff_cleanup_semantic(&self, diffs: &mut Vec<Diff>)
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.
sourcepub fn diff_cleanup_efficiency(&self, diffs: &mut Vec<Diff>)
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.
sourcepub fn diff_text1(&self, diffs: &[Diff]) -> Chars
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.
sourcepub fn diff_text2(&self, diffs: &[Diff]) -> Chars
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.
sourcepub fn diff_xindex(&self, diffs: &[Diff], loc: usize) -> usize
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.
pub fn diff_levenshtein(&self, diffs: &[Diff]) -> usize
pub fn diff_to_delta(&self, diffs: &[Diff]) -> String
pub fn diff_from_delta(&self, _text1: &mut Chars, _delta: &str)
pub fn diff_to_html(&self, diffs: &[Diff]) -> String
sourcepub fn diff_bisect(&mut self, text1: &[char], text2: &[char]) -> Vec<Diff> ⓘ
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.
sourcepub fn diff_main(
&self,
text1: &[char],
text2: &[char],
checklines: bool
) -> Vec<Diff> ⓘ
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.
sourcepub fn diff_linemode(&mut self, text1: &[char], text2: &[char]) -> Vec<Diff> ⓘ
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.