• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

difflib/H10-Jan-2016-

.travis.ymlH A D10-Jan-201634

LICENSEH A D10-Jan-20161.4 KiB

README.mdH A D10-Jan-20161.1 KiB

README.md

1go-difflib
2==========
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)
6
7Go-difflib is a partial port of python 3 difflib package. Its main goal
8was to make unified and context diff available in pure Go, mostly for
9testing purposes.
10
11The following class and functions (and related tests) have be ported:
12
13* `SequenceMatcher`
14* `unified_diff()`
15* `context_diff()`
16
17## Installation
18
19```bash
20$ go get github.com/pmezard/go-difflib/difflib
21```
22
23### Quick Start
24
25Diffs are configured with Unified (or ContextDiff) structures, and can
26be output to an io.Writer or returned as a string.
27
28```Go
29diff := UnifiedDiff{
30    A:        difflib.SplitLines("foo\nbar\n"),
31    B:        difflib.SplitLines("foo\nbaz\n"),
32    FromFile: "Original",
33    ToFile:   "Current",
34    Context:  3,
35}
36text, _ := GetUnifiedDiffString(diff)
37fmt.Printf(text)
38```
39
40would output:
41
42```
43--- Original
44+++ Current
45@@ -1,3 +1,3 @@
46 foo
47-bar
48+baz
49```
50
51