1
1
go-difflib
2
2
==========
3
3
4
- [ ![ Build Status] ( https://travis-ci.org/pmezard/go-difflib.png?branch=master )] ( https://travis-ci.org/pmezard/go-difflib )
5
- [ ![ GoDoc] ( https://godoc.org/github.com/pmezard/go-difflib/difflib?status.svg )] ( https://godoc.org/github.com/pmezard/go-difflib/difflib )
4
+ The previous owner of this project (pmezard) did not have the time to continue
5
+ working on it. Additionally I (ianbruene) needed additional ported features.
6
+
7
+ I have taken over maintenance and further development of the project
8
+
9
+ [ ![ GoDoc] ( https://godoc.org/github.com/ianbruene/go-difflib/difflib?status.svg )] ( https://godoc.org/github.com/ianbruene/go-difflib/difflib )
6
10
7
11
Go-difflib is a partial port of python 3 difflib package. Its main goal
8
- was to make unified and context diff available in pure Go, mostly for
9
- testing purposes.
12
+ is to make unified and context diff available in pure Go.
10
13
11
14
The following class and functions (and related tests) have be ported:
12
15
13
16
* ` SequenceMatcher `
17
+ * ` Differ `
14
18
* ` unified_diff() `
15
19
* ` context_diff() `
16
20
17
21
## Installation
18
22
19
23
``` bash
20
- $ go get github.com/pmezard /go-difflib/difflib
24
+ $ go get github.com/ianbruene /go-difflib/difflib
21
25
```
22
26
23
- ### Quick Start
27
+ ### UnifiedDiff Quick Start
24
28
25
29
Diffs are configured with Unified (or ContextDiff) structures, and can
26
30
be output to an io.Writer or returned as a string.
27
31
28
32
``` Go
29
- diff := UnifiedDiff {
33
+ diff := difflib. UnifiedDiff {
30
34
A : difflib.SplitLines (" foo\n bar\n " ),
31
35
B : difflib.SplitLines (" foo\n baz\n " ),
32
36
FromFile : " Original" ,
33
37
ToFile : " Current" ,
34
38
Context : 3 ,
35
39
}
36
- text , _ := GetUnifiedDiffString (diff)
40
+ text , _ := difflib. GetUnifiedDiffString (diff)
37
41
fmt.Printf (text)
38
42
```
39
43
@@ -48,3 +52,23 @@ would output:
48
52
+baz
49
53
```
50
54
55
+ ### Differ Quick Start
56
+
57
+ Differ has been implemented primarily for the Compare() function at this time.
58
+
59
+ ``` Go
60
+ out , err := diff.Compare (
61
+ []string {" foo\n " , " bar\n " , " baz\n " },
62
+ []string {" foo\n " , " bar1\n " , " asdf\n " , " baz\n " })
63
+ ```
64
+
65
+ would output:
66
+
67
+ ```
68
+ foo
69
+ - bar
70
+ + bar1
71
+ ? +
72
+ + asdf
73
+ baz
74
+ ```
0 commit comments