File tree Expand file tree Collapse file tree 2 files changed +42
-6
lines changed Expand file tree Collapse file tree 2 files changed +42
-6
lines changed Original file line number Diff line number Diff line change 1
- Here is a partial port of python 3 difflib package. Its main goal was to
2
- make available a unified diff implementation, mostly for testing purposes.
1
+ go- difflib
2
+ ==========
3
3
4
- The following class and functions have be ported:
4
+ Go-difflib is a partial port of python 3 difflib package. Its main goal
5
+ was to make unified and context diff available in pure Go, mostly for
6
+ testing purposes.
7
+
8
+ The following class and functions (and related tests) have be ported:
5
9
6
10
* ` SequenceMatcher `
7
11
* ` unified_diff() `
8
12
* ` context_diff() `
9
13
10
- Related doctests and unittests have been ported as well.
14
+ ## Installation
15
+
16
+ ``` bash
17
+ $ go get github.com/pmezard/go-difflib/difflib
18
+ ```
19
+
20
+ ### Quick Start
21
+
22
+ Diffs are configured with Unified (or ContextDiff) structures, and can
23
+ be output to an io.Writer or returned as a string.
24
+
25
+ ``` Go
26
+ diff := UnifiedDiff {
27
+ A : difflib.SplitLines (" foo\n bar\n " ),
28
+ B : difflib.SplitLines (" foo\n baz\n " ),
29
+ FromFile : " Original" ,
30
+ ToFile : " Current" ,
31
+ Context : 3 ,
32
+ }
33
+ text , _ := GetUnifiedDiffString (diff)
34
+ fmt.Printf (text)
35
+ ```
36
+
37
+ would output:
38
+
39
+ ```
40
+ --- Original
41
+ +++ Current
42
+ @@ -1,3 +1,3 @@
43
+ foo
44
+ -bar
45
+ +baz
46
+ ```
11
47
12
- I have barely used to code yet so do not consider it being production-ready.
13
- The API is likely to evolve too.
Original file line number Diff line number Diff line change 7
7
//
8
8
// - unified_diff
9
9
//
10
+ // - context_diff
11
+ //
10
12
// Getting unified diffs was the main goal of the port. Keep in mind this code
11
13
// is mostly suitable to output text differences in a human friendly way, there
12
14
// are no guarantees generated diffs are consumable by patch(1).
You can’t perform that action at this time.
0 commit comments