mirror of
https://github.com/pointfreeco/swift-custom-dump.git
synced 2026-04-07 19:17:35 +00:00
* Abbreviate enums in diffs We added the ability to abbreviate nested dumps in #71, but this didn't transfer to diffs. * wip * Fix for old Swift runtime
26 lines
828 B
Swift
26 lines
828 B
Swift
import Foundation
|
|
|
|
extension String {
|
|
func indenting(by count: Int) -> String {
|
|
self.indenting(with: String(repeating: " ", count: count))
|
|
}
|
|
|
|
func indenting(with prefix: String) -> String {
|
|
guard !prefix.isEmpty else { return self }
|
|
return "\(prefix)\(self.replacingOccurrences(of: "\n", with: "\n\(prefix)"))"
|
|
}
|
|
|
|
func hashCount(isMultiline: Bool) -> Int {
|
|
let (quote, offset) = isMultiline ? ("\"\"\"", 2) : ("\"", 0)
|
|
var substring = self[...]
|
|
var hashCount = 0
|
|
let pattern = "(\(quote)[#]*)"
|
|
while let range = substring.range(of: pattern, options: .regularExpression) {
|
|
let count = substring.distance(from: range.lowerBound, to: range.upperBound) - offset
|
|
hashCount = max(count, hashCount)
|
|
substring = substring[range.upperBound...]
|
|
}
|
|
return hashCount
|
|
}
|
|
}
|