Diff - Simple diffing library in pure Swift

Overview

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!

You might also like...
A simple swift package that provides a Swift Concurrency equivalent to `@Published`.

AsyncValue This is a simple package that provides a convenience property wrapper around AsyncStream that behaves almost identically to @Published. Ins

 Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

RandomKit is a Swift framework that makes random data generation simple and easy.
RandomKit is a Swift framework that makes random data generation simple and easy.

RandomKit is a Swift framework that makes random data generation simple and easy. Build Status Installation Compatibility Swift Package Manager CocoaP

A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.
A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.

SwiftPokedex SwiftPokedex is a simple Pokedex app written by Viktor Gidlöf in Swift that implements the PokeAPI. For full documentation and implementa

A simple Swift package for counting the Syllables in a sentence.

A simple Swift package for counting the Syllables in a sentence.

A simple Swift utility for producing pseudolocalized strings.
A simple Swift utility for producing pseudolocalized strings.

Build your App UI to adapt and respond to translations, and find localization bugs!

AnalyticsKit for Swift is designed to combine various analytical services into one simple tool.

🦋 AnalyticsKit AnalyticsKit for Swift is designed to combine various analytical services into one simple tool. To send information about a custom eve

A simple solution for tiring [weak self] in swift

Weakifiable A simple solution for tiring [weak self] in swift Usage give this repo a Star ⭐️ Add EBWeakifiable to your Project. simply after each clos

A simple, but efficient CSV Parser, written in Swift.

CSV CSV.swift is a powerful swift library for parsing CSV files that supports reading as [String], [String: String] and Decodable, without sacrificing

Releases(v0.2.5)
Owner
Sam Soffes
Sam Soffes
🦀Amazingly incredible extraordinary lightning fast diffing in Swift

DeepDiff ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut man

Khoa 2k Dec 29, 2022
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

kelvin 4 Aug 14, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Pure Declarative Programming in Swift, Among Other Things

Basis The Basis is an exploration of pure declarative programming and reasoning in Swift. It by no means contains idiomatic code, but is instead inten

TypeLift 314 Dec 22, 2022
A utility that reminds your iPhone app's users to review the app written in pure Swift.

SwiftRater SwiftRater is a class that you can drop into any iPhone app that will help remind your users to review your app on the App Store/in your ap

Takeshi Fujiki 289 Dec 12, 2022
A Powerful , Extensible CSS Parser written in pure Swift.

A Powerful , Extensible CSS Parser written in pure Swift.

null 273 Sep 9, 2022
Created a Tic Tac Toe game with pure swift that runs within zsh shell.

Swift TicTacToe Created a Tic Tac Toe game with pure swift that runs within zsh shell. The computer is actually really hard to beat and it ends up bei

Ethan 0 Nov 25, 2021
Angle is a simple Swift library that provides Angle structure representing angles.

Angle is a simple Swift library that provides Angle structure representing angles. It handles angles using circular measure by default but is al

Geonu Jeon 2 Nov 30, 2021
StoredIn is a simple property wrapper library to store any value in anywhere

StoredIn StoredIn is a simple property wrapper library to store any value in anywhere. Installation Please use the Swift Package Manager. dependencies

Henrique Sasaki Yuya 2 Jul 4, 2022