From 4d91f93589497b4a43be12f5039d5f2983ae56ad Mon Sep 17 00:00:00 2001 From: Patrick Mezard Date: Sat, 23 Nov 2013 20:53:50 +0100 Subject: [PATCH] README: make it less experimental, add examples --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++------ difflib/difflib.go | 2 ++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index aa7dba9..937005e 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,47 @@ -Here is a partial port of python 3 difflib package. Its main goal was to -make available a unified diff implementation, mostly for testing purposes. +go-difflib +========== -The following class and functions have be ported: +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()` -Related doctests and unittests have been ported as well. +## Installation + +```bash +$ 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. + +```Go +diff := UnifiedDiff{ + A: difflib.SplitLines("foo\nbar\n"), + B: difflib.SplitLines("foo\nbaz\n"), + FromFile: "Original", + ToFile: "Current", + Context: 3, +} +text, _ := GetUnifiedDiffString(diff) +fmt.Printf(text) +``` + +would output: + +``` +--- Original ++++ Current +@@ -1,3 +1,3 @@ + foo +-bar ++baz +``` -I have barely used to code yet so do not consider it being production-ready. -The API is likely to evolve too. diff --git a/difflib/difflib.go b/difflib/difflib.go index e5221e4..5d3d444 100644 --- a/difflib/difflib.go +++ b/difflib/difflib.go @@ -7,6 +7,8 @@ // // - unified_diff // +// - context_diff +// // Getting unified diffs was the main goal of the port. Keep in mind this code // is mostly suitable to output text differences in a human friendly way, there // are no guarantees generated diffs are consumable by patch(1).