0
Fork 0
mirror of https://github.com/pmezard/go-difflib.git synced 2026-11-16 19:09:49 +00:00
Partial port of Python difflib package to Go
Find a file
Patrick Mézard 5d4384ee4f
Merge pull request #10 from justbuchanan/master
Fixed minor mistake in readme example
History 2018-12-26 11:54:42 +01:00
difflib tests: test header is omitted if file names are empty 2016-01-10 11:52:04 +01:00
LICENSE Initial port with SequenceMatcher and unified_diff() 2013-10-21 22:50:12 +02:00
README.md Merge pull request #10 from justbuchanan/master 2018-12-26 11:54:42 +01:00

go-difflib

THIS PACKAGE IS NO LONGER MAINTAINED.

At this point, I have no longer the time nor the interest to work on go-difflib. I apologize for the inconvenience.

GoDoc

Go-difflib is a partial port of python 3 difflib package. Its main goal was to make unified and context diff available in pure Go, mostly for testing purposes.

The following class and functions (and related tests) have be ported:

  • SequenceMatcher
  • unified_diff()
  • context_diff()

Installation

$ go get github.com/pmezard/go-difflib/difflib

Quick Start

Diffs are configured with Unified (or ContextDiff) structures, and can be output to an io.Writer or returned as a string.

diff := difflib.UnifiedDiff{
    A:        difflib.SplitLines("foo\nbar\n"),
    B:        difflib.SplitLines("foo\nbaz\n"),
    FromFile: "Original",
    ToFile:   "Current",
    Context:  3,
}
text, _ := difflib.GetUnifiedDiffString(diff)
fmt.Printf(text)

would output:

--- Original
+++ Current
@@ -1,3 +1,3 @@
 foo
-bar
+baz