GitXplorerGitXplorer
s

Diff

public
122 stars
10 forks
0 issues

Commits

List of commits on branch master.
Unverified
e8f9b0a616f582e9c62e1b94cf21156f5567d1b9

Update Travis config

ssoffes committed 7 years ago
Unverified
77ba3a7344e47a1e8508d921800577ee6ea4cdf6

Backwards compatible

ssoffes committed 7 years ago
Unverified
f6ecda79c4869b78c8553e6f56f3e34d89409571

Update Package.swift for Swift 4

ssoffes committed 7 years ago
Unverified
b79a7c3ae2f36e25ea9c976d13ffb7040bf9ca84

Add gitignore

ssoffes committed 7 years ago
Unverified
d79b83d62a85014ff995a0bb0349bb293f2ca2cc

Swift 4

ssoffes committed 7 years ago
Unverified
2f56db89a2f9737bbc6ab5249be6b050ae7e4914

Version 0.2.1

ssoffes committed 8 years ago

README

The README file for this repository.

Diff

Version Build Status Carthage compatible

Simple diffing library in pure Swift.

Installing

You can use Carthage or Swift Package Manager to install Diff.

Usage

Start by importing the package:

import Diff

Same

If there is no difference, the diff will be nil.

diff("Hello", "Hello") // nil

For the sake of brevity, we'll ! the rest of the examples since we know they're different.

Insert

let (range, string) = diff("Hello world", "Hello there world")!
// range: 6..<6
// string: "there "

Remove

let (range, string) = diff("Hello there world", "Hello world")!
// range: 6..<12
// string: ""

Other Types

Diff can diff any array. Here's an array of things that conform to Equatable:

let (range, replacement) = diff([1, 2, 3], [1, 2, 3, 4])!
// range: 3..<3
// replacement: [4]

You can even use arrays of anything as long as you can compare them:

let before: [Foo] = [a, b]
let after: [Foo] = [b]
let (range, replacement) = diff(before, after, compare: Foo.compare)!
// range: 0..<1
// replacement: []

Development

If you want to contribute to Diff, please write a test.

Building and running the tests locally with SPM is easy:

$ git clone https://github.com/soffes/Diff
$ cd Diff
$ swift build
$ swift test

Thanks

Thanks to Jonathan Clem for the original algorithm and Caleb Davenport for inspiration for the generics implementation and help debugging a few edge cases!