@@ -51,7 +51,7 @@ extension RFC_1035 {
5151 /// - rawValue: The raw domain name (unchecked)
5252 /// - labels: Pre-validated labels
5353 init (
54- __unchecked: Void ,
54+ __unchecked _ : Void ,
5555 rawValue: String ,
5656 labels: [ RFC_1035 . Domain . Label ]
5757 ) {
@@ -117,7 +117,7 @@ extension RFC_1035.Domain: UInt8.ASCII.Serializing {
117117 ///
118118 /// - Parameter bytes: The ASCII byte representation of the domain
119119 /// - Throws: `RFC_1035.Domain.Error` if the bytes are malformed
120- public init ( ascii bytes: [ UInt8 ] ) throws ( Error) {
120+ public init < Bytes : Collection > ( ascii bytes: Bytes ) throws ( Error) where Bytes . Element == UInt8 {
121121 // Empty check
122122 guard !bytes. isEmpty else {
123123 throw Error . empty
@@ -131,26 +131,29 @@ extension RFC_1035.Domain: UInt8.ASCII.Serializing {
131131 // Split on dots (0x2E) and parse each label
132132 var labels : [ RFC_1035 . Domain . Label ] = [ ]
133133 var currentStart = bytes. startIndex
134+ var currentIndex = bytes. startIndex
134135
135- for (index, byte) in bytes. enumerated ( ) {
136- if byte == . ascii. period {
137- let labelBytes = Array ( bytes [ currentStart..< index] )
138- if !labelBytes. isEmpty {
136+ while currentIndex < bytes. endIndex {
137+ if bytes [ currentIndex] == . ascii. period {
138+ // Found a dot - extract label
139+ if currentStart < currentIndex {
140+ let labelBytes = bytes [ currentStart..< currentIndex]
139141 do {
140- labels. append ( try RFC_1035 . Domain. Label ( ascii: labelBytes) )
142+ try labels. append ( RFC_1035 . Domain. Label ( ascii: labelBytes) )
141143 } catch {
142144 throw Error . invalidLabel ( error)
143145 }
144146 }
145- currentStart = bytes. index ( after: index )
147+ currentStart = bytes. index ( after: currentIndex )
146148 }
149+ currentIndex = bytes. index ( after: currentIndex)
147150 }
148151
149152 // Handle final label (after last dot or entire string if no dots)
150153 if currentStart < bytes. endIndex {
151- let labelBytes = Array ( bytes [ currentStart... ] )
154+ let labelBytes = bytes [ currentStart... ]
152155 do {
153- labels. append ( try RFC_1035 . Domain. Label ( ascii: labelBytes) )
156+ try labels. append ( RFC_1035 . Domain. Label ( ascii: labelBytes) )
154157 } catch {
155158 throw Error . invalidLabel ( error)
156159 }
@@ -200,13 +203,13 @@ extension [UInt8] {
200203 ///
201204 /// - Parameter domain: The domain name to serialize
202205 public init ( _ domain: RFC_1035 . Domain ) {
203- self = Array ( domain. rawValue. utf8)
206+ self = Self ( domain. rawValue. utf8)
204207 }
205208}
206209
207210// MARK: - Protocol Conformances
208211
209- extension RFC_1035 . Domain : RawRepresentable { }
212+ extension RFC_1035 . Domain : UInt8 . ASCII . RawRepresentable { }
210213extension RFC_1035 . Domain : CustomStringConvertible { }
211214
212215// MARK: - Domain Properties
@@ -242,7 +245,7 @@ extension RFC_1035.Domain {
242245 var newLabels : [ Label ] = [ ]
243246 for component in components {
244247 do {
245- newLabels. append ( try Label ( component) )
248+ try newLabels. append ( Label ( component) )
246249 } catch {
247250 throw Error . invalidLabel ( error)
248251 }
@@ -263,7 +266,7 @@ extension RFC_1035.Domain {
263266
264267 /// Creates a subdomain by prepending new labels
265268 public func addingSubdomain( _ components: String ... ) throws ( Error) -> RFC_1035 . Domain {
266- try self . addingSubdomain ( components)
269+ try addingSubdomain ( components)
267270 }
268271
269272 /// Returns the parent domain by removing the leftmost label
@@ -311,7 +314,7 @@ extension RFC_1035.Domain {
311314 var validatedLabels : [ Label ] = [ ]
312315 for labelString in labelStrings {
313316 do {
314- validatedLabels. append ( try Label ( labelString) )
317+ try validatedLabels. append ( Label ( labelString) )
315318 } catch {
316319 throw Error . invalidLabel ( error)
317320 }
0 commit comments