Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ func (c *Chunk) empty() bool {
// changes required to make A into B. Each line is prefixed with '+', '-', or
// ' ' to indicate if it should be added, removed, or is correct respectively.
func Diff(A, B string) string {
aLines := strings.Split(A, "\n")
bLines := strings.Split(B, "\n")
aLines := splitLines(A)
bLines := splitLines(B)
return Render(DiffChunks(aLines, bLines))
}

// splitLines splits s into lines, returning nil for an empty string
// instead of a slice containing one empty string.
func splitLines(s string) []string {
if s == "" {
return nil
}
return strings.Split(s, "\n")
}

// Render renders the slice of chunks into a representation that prefixes
// the lines with '+', '-', or ' ' depending on whether the line was added,
// removed, or equal (respectively).
Expand Down