mirror of
https://github.com/github/semantic.git
synced 2024-12-25 07:55:12 +03:00
Add a private function to splat out context.
This commit is contained in:
parent
b858c164d8
commit
7ac4c9ee03
@ -7,6 +7,19 @@ private func range(patch: Patch<Term>) -> Range<Int>? {
|
||||
return patch.state.after?.extract.range
|
||||
}
|
||||
|
||||
private func unified(range: Range<Int>, children: [(String, Range<Int>?)], source: String) -> String {
|
||||
var previous = range.startIndex
|
||||
var out: String = ""
|
||||
for (string, range) in children {
|
||||
if let range = range {
|
||||
out += String(source.utf16[previous..<range.startIndex])
|
||||
previous = range.endIndex
|
||||
}
|
||||
out += string
|
||||
}
|
||||
return out + String(source.utf16[previous..<range.endIndex])
|
||||
}
|
||||
|
||||
func unified(diff: Diff, before: String, after: String) -> String {
|
||||
return diff.map { (unified($0, source: after), range($0)) }.cata { info, syntax in
|
||||
switch syntax {
|
||||
|
Loading…
Reference in New Issue
Block a user