Exemple #1
0
    public string DoDiff() {
		string[] origLines = origString.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
        string[] newLines = newString.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
		var diffs = new Diff( origLines, newLines );
	    var formatter = new TableDiffFormatter();
        return formatter.format(diffs);
    }
Exemple #2
0
	/**
	 * Format a diff.
	 *
	 * @param diff object A Diff object.
	 * @return string The formatted output.
	 */
	public string format( Diff diff ) {
		
		int x0 = 0, y0 = 0;
		int xi = 1, yi = 1;
		List<_DiffOp> block = new List<_DiffOp>();
		List<string> context = new List<string>();

		int nlead = leading_context_lines;
		int ntrail = trailing_context_lines;

		this._start_diff();

		foreach (var edit in diff.edits ) {
			if ( edit.type == DiffType.Copy ) {
				if ( block.Any() ) {
					if ( edit.orig.Count() <= nlead + ntrail ) {
						block.Add(edit);
					}
					else {
						if ( ntrail != 0 ) {
							context = edit.orig.Take(ntrail).ToList();
							block.Add(new _DiffOp_Copy( context ));
						}
						this._block( x0, ntrail + xi - x0,
						y0, ntrail + yi - y0,
						block );
						block.Clear();
					}
				}
				context = edit.orig;
			}
			else {
				if (!block.Any()) {
					context = context.Skip(context.Count - nlead).ToList();
					x0 = xi - context.Count;
					y0 = yi - context.Count;
					block.Clear();
					if ( context.Count > 0 )
						{block.Add(new _DiffOp_Copy( context ));}
				}
				block.Add(edit);
			}

			if ( edit.orig.Count > 0 )
			{ xi += edit.orig.Count ; }
			if ( edit.closing.Count > 0 )
			{ yi += edit.closing.Count;}
		}

		if ( block.Count > 0 )
		{
			this._block( x0, xi - x0,
			y0, yi - y0,
			block );
		}
		
		return _end_diff();
	}