2024-07-31 17:53:23 -07:00
|
|
|
//
|
|
|
|
|
// StringUtilities.swift
|
|
|
|
|
// App
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 7/31/24.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
extension String {
|
|
|
|
|
internal func middleTruncatedString(maximumLength: Int) -> String {
|
|
|
|
|
if maximumLength > self.count {
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compute replacement range
|
|
|
|
|
let pivot = self.count / 2
|
|
|
|
|
let truncationLength = self.count - maximumLength
|
|
|
|
|
|
|
|
|
|
let pivotIndex = self.index(startIndex, offsetBy: pivot)
|
|
|
|
|
let startIndex = self.index(pivotIndex, offsetBy: -truncationLength / 2)
|
|
|
|
|
let endIndex = self.index(pivotIndex, offsetBy: truncationLength / 2)
|
|
|
|
|
|
|
|
|
|
return replacingCharacters(in: startIndex..<endIndex, with: "…")
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-05 18:09:04 -07:00
|
|
|
|
|
|
|
|
extension URL {
|
|
|
|
|
internal var securityOrigin: String {
|
|
|
|
|
// TODO: This could be smarter…
|
|
|
|
|
return self.host() ?? ""
|
|
|
|
|
}
|
|
|
|
|
}
|