/// <summary> /// A semantic cleanup rewrites the diff, expanding it into a more human-readable format. /// </summary> /* For example, the diff of "mouse" and "sofas" is [(-1, "m"), (1, "s"), (0, "o"), (-1, "u"), (1, "fa"), (0, "s"), (-1, "e")]. * While this is the optimum diff, it is difficult for humans to understand. The above example would become: [(-1, "mouse"), (1, "sofas")]. If a diff is to be human-readable, it * should be passed to diff_cleanupSemantic */ public void CleanupSemantic() { if (diffs == null) { return; } diffMatchPatch.diff_cleanupSemantic(diffs); }
private static string GetPrettyHtmlDiff(string text1, string text2) { if (text1 == null) { text1 = ""; } if (text2 == null) { text2 = ""; } var diffs = Dmp.diff_main(text1, text2); Dmp.diff_cleanupSemantic(diffs); return(Dmp.diff_prettyHtml(diffs)); }
private void PopulateObjectDefinitions(string objDefSource, string objDefTarget, ComparisonObjectType objType, ComparisonObjectStatus objStatus) { try { IterateJson(txtSourceObjectDefinition, objDefSource); IterateJson(txtTargetObjectDefinition, objDefTarget); } catch (Exception) { txtSourceObjectDefinition.Text = ""; txtSourceObjectDefinition.Text = objDefSource; txtTargetObjectDefinition.Text = ""; txtTargetObjectDefinition.Text = objDefTarget; } #region Difference Highlighting if (objStatus == ComparisonObjectStatus.DifferentDefinitions || (objStatus == ComparisonObjectStatus.SameDefinition && objType == ComparisonObjectType.Perspective && _comparisonInfo.OptionsInfo.OptionMergePerspectives) || (objStatus == ComparisonObjectStatus.SameDefinition && objType == ComparisonObjectType.Culture && _comparisonInfo.OptionsInfo.OptionMergeCultures) ) { _diffs = _diff.diff_main(objDefSource, objDefTarget); _diff.diff_cleanupSemantic(_diffs); //_diff.diff_cleanupSemanticLossless(_diffs); //_diff.diff_cleanupEfficiency(_diffs); // NG: Evaluate if this needs to be added //Are we merging perspectives/cultures? if ((objType == ComparisonObjectType.Perspective && _comparisonInfo.OptionsInfo.OptionMergePerspectives) || (objType == ComparisonObjectType.Culture && _comparisonInfo.OptionsInfo.OptionMergeCultures) ) { _chunklistSource = CollectChunks(source: true, backColors: _backColorsMerge); _chunklistTarget = CollectChunks(source: false, backColors: _backColorsMerge); //If same definition with merge perspectives/cultures option, just want to highlight differences in target that will not be applied, so do not paint chunks for source if (objStatus == ComparisonObjectStatus.DifferentDefinitions) { PaintChunks(txtSourceObjectDefinition, _chunklistSource); } PaintChunks(txtTargetObjectDefinition, _chunklistTarget); } else { _chunklistSource = CollectChunks(source: true, backColors: _backColors); _chunklistTarget = CollectChunks(source: false, backColors: _backColors); PaintChunks(txtSourceObjectDefinition, _chunklistSource); PaintChunks(txtTargetObjectDefinition, _chunklistTarget); } } #endregion //select 1st characters so not scrolled at bottom if (txtSourceObjectDefinition.Text != "") { txtSourceObjectDefinition.SelectionStart = 0; txtSourceObjectDefinition.SelectionLength = 0; txtSourceObjectDefinition.ScrollToCaret(); } if (txtTargetObjectDefinition.Text != "") { txtTargetObjectDefinition.SelectionStart = 0; txtTargetObjectDefinition.SelectionLength = 0; txtTargetObjectDefinition.ScrollToCaret(); } }