Update README
Using the Myers's Difference Algorithm to compare differences between two equatable element
the Myers's Difference Algorithm
import Sdifft let source = "b" let target = "abcd" let diff = Diff(source: from, target: to) diff.scripts // [.insert(into: 3), .insert(into: 2), .same(into: 1), .insert(into: 0)] /// Get diff attributedString let diffAttributes = DiffAttributes( insert: [.backgroundColor: UIColor.green], delete: [.backgroundColor: UIColor.red], same: [.backgroundColor: UIColor.white] ) let attributedString = NSAttributedString(source: source, target: target, attributes: diffAttributes) // output -> // a{green}b{black}cd{green}
import Sdifft let source = ["Hello"] let target = ["Hello", "World", "!"] let attributedString = NSAttributedString(source: source, target: target, attributes: diffAttributes) { script, string in let string = NSMutableAttributedString(attributedString: string) string.append(NSAttributedString(string: "\n")) switch script { case .delete: string.insert(NSAttributedString(string: "- "), at: 0) case .insert: string.insert(NSAttributedString(string: "+ "), at: 0) case .same: string.insert(NSAttributedString(string: " "), at: 0) } return string } // output -> // Hello // + World{green} // + !{green}
// Package.swift let package = Package( name: "XXX", dependencies: [ .Package(url: "https://github.com/Wzxhaha/Sdifft", majorVersion: 2) ] )
// Cartfile github "Wzxhaha/Sdifft"
Sdifft is released under the MIT license. See LICENSE for details.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Sdifft
Using
the Myers's Difference Algorithm
to compare differences between two equatable elementExample(String)
Example(Line)
Installation
Swift Package Manager
Carthage
License
Sdifft is released under the MIT license. See LICENSE for details.