pub struct Dmp {
pub diff_timeout: Option<f32>,
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,
pub segmentation: Segmentation,
pub word_mode: bool,
}Fields§
§diff_timeout: Option<f32>§edit_cost: i32§match_distance: i32§patch_margin: i32§match_maxbits: i32§match_threshold: f32§patch_delete_threshold: f32§segmentation: Segmentation§word_mode: boolImplementations§
Source§impl Dmp
impl Dmp
Sourcepub fn diff_xindex(&mut self, diffs: &Vec<Diff>, loc: i32) -> i32
pub fn diff_xindex(&mut self, diffs: &Vec<Diff>, loc: i32) -> i32
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.
Sourcepub fn diff_text1(&mut self, diffs: &mut Vec<Diff>) -> String
pub fn diff_text1(&mut self, diffs: &mut Vec<Diff>) -> String
Compute and return the source text (all equalities and deletions).
Args: diffs: Vectoe of diff object.
Returns: Source text.
Sourcepub fn diff_text2(&mut self, diffs: &mut Vec<Diff>) -> String
pub fn diff_text2(&mut self, diffs: &mut Vec<Diff>) -> String
Compute and return the destination text (all equalities and insertions).
Args: diffs: Vector of diff object.
Returns: destination text.
Sourcepub fn diff_levenshtein(&mut self, diffs: &Vec<Diff>) -> i32
pub fn diff_levenshtein(&mut self, diffs: &Vec<Diff>) -> i32
Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
Args: diffs: Vector of diff object.
Returns: Number of changes.
Source§impl Dmp
impl Dmp
pub fn diff_cleanup_semantic(&mut self, diffs: &mut Vec<Diff>)
pub fn diff_cleanup_semantic_lossless(&mut self, diffs: &mut Vec<Diff>)
pub fn diff_cleanup_efficiency(&mut self, diffs: &mut Vec<Diff>)
pub fn diff_cleanup_merge(&mut self, diffs: &mut Vec<Diff>)
Source§impl Dmp
impl Dmp
Sourcepub fn diff_todelta(&mut self, diffs: &mut Vec<Diff>) -> String
pub fn diff_todelta(&mut self, diffs: &mut Vec<Diff>) -> String
Crush the diff into an encoded string which describes the operations required to transform text1 into text2. E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert ‘ing’. Operations are tab-separated. Inserted text is escaped using %xx notation.
Args: diffs: Vector of diff object.
Returns: Delta text.
Sourcepub fn diff_from_delta(&mut self, text1: &str, delta: &str) -> Vec<Diff>
pub fn diff_from_delta(&mut self, text1: &str, delta: &str) -> Vec<Diff>
Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.
Args: text1: Source string for the diff. delta: Delta text.
Returns: Vector of diff object.
Panics on invalid input (malformed escape, bad length, or a delta that does not consume text1 exactly).
Source§impl Dmp
impl Dmp
Sourcepub fn diff_main(
&mut self,
text1: &str,
text2: &str,
checklines: bool,
) -> Vec<Diff>
pub fn diff_main( &mut self, text1: &str, text2: &str, checklines: bool, ) -> Vec<Diff>
Find the differences between two chars. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.
Args: text1: Old chars to be diffed. text2: New chars 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: &Vec<char>,
text2: &Vec<char>,
) -> Vec<Diff>
pub fn diff_linemode( &mut self, text1: &Vec<char>, text2: &Vec<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.
Sourcepub fn diff_bisect(&mut self, char1: &Vec<char>, char2: &Vec<char>) -> Vec<Diff>
pub fn diff_bisect(&mut self, char1: &Vec<char>, char2: &Vec<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.
pub fn diff_common_prefix( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> i32
pub fn diff_common_suffix( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> i32
pub fn diff_common_overlap( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> i32
Sourcepub fn diff_half_match(
&mut self,
text1: &Vec<char>,
text2: &Vec<char>,
) -> Vec<String>
pub fn diff_half_match( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> Vec<String>
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.
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§impl Dmp
impl Dmp
Sourcepub fn match_main(&mut self, text1: &str, patern1: &str, loc: i32) -> i32
pub fn match_main(&mut self, text1: &str, patern1: &str, loc: i32) -> i32
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: &Vec<char>,
patern: &Vec<char>,
loc: i32,
) -> i32
pub fn match_bitap( &mut self, text: &Vec<char>, patern: &Vec<char>, loc: i32, ) -> i32
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.
Sourcepub fn match_bitap_score(
&mut self,
e: i32,
x: i32,
loc: i32,
patern: &Vec<char>,
) -> f32
pub fn match_bitap_score( &mut self, e: i32, x: i32, loc: i32, patern: &Vec<char>, ) -> f32
Compute and return the score for a match with e errors and x location. Accesses loc and pattern through being a closure.
Args: e: Number of errors in match. x: Location of match.
Returns: Overall score for match (0.0 = good, 1.0 = bad).
Sourcepub fn match_alphabet(&mut self, patern: &Vec<char>) -> HashMap<char, i32>
pub fn match_alphabet(&mut self, patern: &Vec<char>) -> HashMap<char, i32>
Initialise the alphabet for the Bitap algorithm.
Args: pattern: The text to encode.
Returns: Hash of character locations. Public i32 view of the internal u64 masks; bit 31 lands in the sign bit exactly as the pre-rewrite release builds computed it.
Source§impl Dmp
impl Dmp
Sourcepub fn patch_add_context(&mut self, patch: &mut Patch, text: &mut Vec<char>)
pub fn patch_add_context(&mut self, patch: &mut Patch, text: &mut Vec<char>)
Increase the context until it is unique, but don’t let the pattern expand beyond Match_MaxBits.
Args: patch: The patch to grow. text: Source text.
Sourcepub fn patch_make1(&mut self, text1: &str, text2: &str) -> Vec<Patch>
pub fn patch_make1(&mut self, text1: &str, text2: &str) -> Vec<Patch>
Compute a list of patches to turn text1 into text2. compute diffs. Args: text1: First string. text2: Second string. Returns: Vector of Patch objects.
Sourcepub fn patch_make2(&mut self, diffs: &mut Vec<Diff>) -> Vec<Patch>
pub fn patch_make2(&mut self, diffs: &mut Vec<Diff>) -> Vec<Patch>
Compute a list of patches to turn text1 into text2. Use diffs to compute first text.
Args: diffs: Vector od diff object. Returns: Vector of Patch objects.
Sourcepub fn patch_make3(
&mut self,
text1: &str,
_text2: &str,
diffs: &mut Vec<Diff>,
) -> Vec<Patch>
pub fn patch_make3( &mut self, text1: &str, _text2: &str, diffs: &mut Vec<Diff>, ) -> Vec<Patch>
Compute a list of patches to turn text1 into text2.
Args: text1: First string. text2: Second string. diffs: Vector of diff.
Returns: Vector of Patch objects.
Sourcepub fn patch_make4(&mut self, text1: &str, diffs: &mut Vec<Diff>) -> Vec<Patch>
pub fn patch_make4(&mut self, text1: &str, diffs: &mut Vec<Diff>) -> Vec<Patch>
Compute a list of patches to turn text1 into text2.
Args: text1: First string. diffs: Vector of diff object. Returns: Array of Patch objects.
Sourcepub fn patch_deep_copy(&mut self, patches: &mut Vec<Patch>) -> Vec<Patch>
pub fn patch_deep_copy(&mut self, patches: &mut Vec<Patch>) -> Vec<Patch>
Given an Vector of patches, return another Vector that is identical.
Args: patches: Vector of Patch objects.
Returns: Vector of Patch objects.
pub fn patch_apply( &mut self, patches: &mut Vec<Patch>, source_text: &str, ) -> (Vec<char>, Vec<bool>)
Sourcepub fn patch_add_padding(&mut self, patches: &mut Vec<Patch>) -> Vec<char>
pub fn patch_add_padding(&mut self, patches: &mut Vec<Patch>) -> Vec<char>
Add some padding on text start and end so that edges can match something. Intended to be called only from within patch_apply.
Args: patches: Array of Patch objects.
Returns: The padding chars added to each side.
Sourcepub fn patch_splitmax(&mut self, patches: &mut Vec<Patch>)
pub fn patch_splitmax(&mut self, patches: &mut Vec<Patch>)
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.
Args: patches: Array of Patch objects.
Sourcepub fn patch_to_text(&mut self, patches: &mut Vec<Patch>) -> String
pub fn patch_to_text(&mut self, patches: &mut Vec<Patch>) -> String
Take a list of patches and return a textual representation.
Args: patches: Vector of Patch objects.
Returns: Text representation of patches.
Sourcepub fn patch_from_text(&mut self, textline: String) -> Vec<Patch>
pub fn patch_from_text(&mut self, textline: String) -> Vec<Patch>
Parse a textual representation of patches and return a list of patch objects.
Args: textline: Text representation of patches.
Returns: Vector of Patch objects.
Panics on malformed patch text.
pub fn patch1_from_text(&mut self, textline: String) -> Patch
Source§impl Dmp
impl Dmp
Sourcepub fn split_by_char(&mut self, text: &str, ch: char) -> Vec<String>
pub fn split_by_char(&mut self, text: &str, ch: char) -> Vec<String>
split the string accoring to given character
Args: text: string we have to split ch: character by which we have to split string
Returns: Vector of string after spliting according to character.
Sourcepub fn split_by_chars(&mut self, text: &str) -> Vec<String>
pub fn split_by_chars(&mut self, text: &str) -> Vec<String>
split the string accoring to given characters “@@ “.
Args: text: string we have to split
Returns: Vector of string after spliting according to characters.