Skip to content

Commit 982fbc3

Browse files
author
Thomas Hambach
committed
Updated documentation
1 parent 683ff72 commit 982fbc3

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

CSharpDiff/Patch/IPatch.cs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using CSharpDiff.Patch.Models;
2+
3+
namespace CSharpDiff.Patch
4+
{
5+
public interface IPatch
6+
{
7+
string[] contextLines(string[] lines);
8+
9+
/// <summary>
10+
/// Create a text version of a unified diff patch.
11+
/// </summary>
12+
/// <param name="oldFileName"></param>
13+
/// <param name="newFileName"></param>
14+
/// <param name="newStr"></param>
15+
/// <param name="oldStr"></param>
16+
/// <param name="oldHeader"></param>
17+
/// <param name="newHeader"></param>
18+
/// <param name="options"></param>
19+
/// <returns></returns>
20+
string create(string oldFileName, string newFileName, string newStr, string oldStr, string oldHeader, string newHeader, PatchOptions options);
21+
22+
/// <summary>
23+
/// Create object of PatchResult that can be consumed by `formatPatch` to create a unified diff.
24+
/// </summary>
25+
/// <param name="oldFileName"></param>
26+
/// <param name="newFileName"></param>
27+
/// <param name="newStr"></param>
28+
/// <param name="oldStr"></param>
29+
/// <param name="oldHeader"></param>
30+
/// <param name="newHeader"></param>
31+
/// <param name="options"></param>
32+
/// <returns></returns>
33+
PatchResult createPatchResult(string oldFileName, string newFileName, string newStr, string oldStr, string oldHeader, string newHeader, PatchOptions options);
34+
35+
/// <summary>
36+
/// Format to unified diff patch using PatchResult
37+
/// </summary>
38+
/// <param name="diff"></param>
39+
/// <returns></returns>
40+
string formatPatch(PatchResult diff);
41+
}
42+
}

CSharpDiff/Patch/Patch.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55

66
namespace CSharpDiff.Patch
77
{
8-
public class Patch
8+
public class Patch : IPatch
99
{
1010
public string[] contextLines(string[] lines)
1111
{
1212
return lines.Select((entry) => { return ' ' + entry; }).ToArray();
1313
}
1414

15-
public PatchResult CreateStructuredPatch(string oldFileName, string newFileName, string newStr, string oldStr, string oldHeader, string newHeader, PatchOptions options)
15+
public string create(string oldFileName, string newFileName, string newStr, string oldStr, string oldHeader, string newHeader, PatchOptions options)
16+
{
17+
var result = createPatchResult(oldFileName, newFileName, newStr, oldStr, oldHeader, newHeader, options);
18+
return formatPatch(result);
19+
}
20+
21+
public PatchResult createPatchResult(string oldFileName, string newFileName, string newStr, string oldStr, string oldHeader, string newHeader, PatchOptions options)
1622
{
1723
var df = new DiffLines();
1824
var diff = df.diff(oldStr, newStr);

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ var text1 = "";
1717
var text2 = "";
1818

1919
var ps = new Patch();
20-
var ds = new Diff();
21-
var patch = ps.CreateStructuredPatch("filename1", "filename2", text1, text2, "", "", new PatchServiceOptions());
22-
var patch = ps.formatPatch(patch);
20+
string patch = ps.create("filename1", "filename2", text1, text2, "header1", "header2", new PatchServiceOptions());
2321
```
2422

2523
### Works Well With

0 commit comments

Comments
 (0)