fix(ios): prettify bonjour endpoint labels
This commit is contained in:
@@ -53,7 +53,7 @@ final class BridgeDiscoveryModel: ObservableObject {
|
||||
return DiscoveredBridge(
|
||||
name: name,
|
||||
endpoint: result.endpoint,
|
||||
debugID: String(describing: result.endpoint))
|
||||
debugID: Self.prettyEndpointDebugID(result.endpoint))
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -72,4 +72,37 @@ final class BridgeDiscoveryModel: ObservableObject {
|
||||
self.bridges = []
|
||||
self.statusText = "Stopped"
|
||||
}
|
||||
|
||||
private static func prettyEndpointDebugID(_ endpoint: NWEndpoint) -> String {
|
||||
self.decodeBonjourEscapes(String(describing: endpoint))
|
||||
}
|
||||
|
||||
private static func decodeBonjourEscapes(_ input: String) -> String {
|
||||
// mDNS / DNS-SD commonly escapes spaces as `\\032` (decimal byte value 32). Make this human-friendly for UI.
|
||||
var out = ""
|
||||
var i = input.startIndex
|
||||
while i < input.endIndex {
|
||||
if input[i] == "\\",
|
||||
let d0 = input.index(i, offsetBy: 1, limitedBy: input.index(before: input.endIndex)),
|
||||
let d1 = input.index(i, offsetBy: 2, limitedBy: input.index(before: input.endIndex)),
|
||||
let d2 = input.index(i, offsetBy: 3, limitedBy: input.index(before: input.endIndex)),
|
||||
input[d0].isNumber,
|
||||
input[d1].isNumber,
|
||||
input[d2].isNumber
|
||||
{
|
||||
let digits = String(input[d0...d2])
|
||||
if let value = Int(digits),
|
||||
let scalar = UnicodeScalar(value)
|
||||
{
|
||||
out.append(Character(scalar))
|
||||
i = input.index(i, offsetBy: 4)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
out.append(input[i])
|
||||
i = input.index(after: i)
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user