Swiftpack.co - Package - Wzxhaha/Sdifft

Sdifft

swift version travis-ci codecov codebeat badge

Using the LCS to compare differences between two strings

Example

impoort Sdifft

let to = "abcd"
let from = "b"
let diff = Diff(from: from, to: to)
/// Get diff modifications
diff.modifications // [(add: "a", delete: nil, same: "b"), (add: "cd", delete: nil, same: nil)]

/// Get same/add/delete
let same = diff.modifications.compactMap { $0.same }
...

/// Get diff attributedString
let diffAttributes = DiffAttributes(add: [.backgroundColor: UIColor.green]], delete: [.backgroundColor: UIColor.red], same: [.backgroundColor: UIColor.white])
let attributedString = NSAttributedString.attributedString(with: diff, attributes: diffAttributes) 

Installation

Swift Package Manager

// Package.swift
let package = Package(
    name: "XXX",
    dependencies: [
        .Package(url: "https://github.com/Wzxhaha/Sdifft", majorVersion: 1)
    ]
)

Carthage

// Cartfile
github "Wzxhaha/Sdifft"

License

Sdifft is released under the MIT license. See LICENSE for details.

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

1.4.1 - Jun 7, 2018

1.4.0 - May 30, 2018

  1. add NSAttributedString+Diff.swift
  2. remove enumBase
  3. update Modification

1.3.0 - May 25, 2018

Because LCS is 'bottom-up', so them need be reversed to get the normal sequence

1.2.2 - May 24, 2018

1.2.1 - May 24, 2018