@@ -89,23 +89,31 @@ AdditiveArithmetic, ExpressibleByIntegerLiteral {
8989}
9090
9191//*============================================================================*
92- // MARK: * Offset x Int [...]
92+ // MARK: * Offset x Int
9393//*============================================================================*
9494
9595public extension Int {
9696
97+ //=------------------------------------------------------------------------=
98+ // MARK: Initializers
99+ //=------------------------------------------------------------------------=
100+
97101 @inlinable @inline ( __always)
98102 init < T> ( _ offset: Offset < T > ) {
99103 self = offset. distance
100104 }
101105}
102106
103107//*============================================================================*
104- // MARK: * Offsets [...]
108+ // MARK: * Offsets
105109//*============================================================================*
106110
107111public protocol Offsets < Index> : Collection {
108112
113+ //=------------------------------------------------------------------------=
114+ // MARK: Utilities
115+ //=------------------------------------------------------------------------=
116+
109117 @inlinable @inline ( __always) func distance< T> (
110118 from start: Index , to end: Index ) -> Offset < T >
111119
@@ -114,11 +122,15 @@ public protocol Offsets<Index>: Collection {
114122}
115123
116124//=----------------------------------------------------------------------------=
117- // MARK: + Details [...]
125+ // MARK: + Details
118126//=----------------------------------------------------------------------------=
119127
120128public extension Offsets {
121129
130+ //=------------------------------------------------------------------------=
131+ // MARK: Utilities
132+ //=------------------------------------------------------------------------=
133+
122134 @inlinable @inline ( __always) func distance< T> (
123135 from start: Index , to end: Index , as type: T . Type ) -> Offset < T > {
124136 distance ( from: start, to: end)
@@ -131,6 +143,10 @@ public extension Offsets {
131143 return lower ..< lower + count
132144 }
133145
146+ //=------------------------------------------------------------------------=
147+ // MARK: Utilities
148+ //=------------------------------------------------------------------------=
149+
134150 @inlinable @inline ( __always) func index< T> (
135151 from start: Index , move distance: Offset < T > , as type: T . Type ) -> Index {
136152 index ( from: start, move: distance)
@@ -149,13 +165,17 @@ public extension Offsets {
149165}
150166
151167//*============================================================================*
152- // MARK: * Offsets x String, String.SubSequence [...]
168+ // MARK: * Offsets x String, String.SubSequence
153169//*============================================================================*
154170
155171extension String : Offsets { }
156172extension String . SubSequence : Offsets { }
157173public extension StringProtocol {
158174
175+ //=------------------------------------------------------------------------=
176+ // MARK: Utilities
177+ //=------------------------------------------------------------------------=
178+
159179 @inlinable @inline ( __always) func distance< T> (
160180 from start: Index , to end: Index ) -> Offset < T > {
161181 T . distance ( from: start, to: end, in: self )
@@ -168,12 +188,16 @@ public extension StringProtocol {
168188}
169189
170190//*============================================================================*
171- // MARK: * Offsets x Snapshot [...]
191+ // MARK: * Offsets x Snapshot
172192//*============================================================================*
173193
174194extension Snapshot : Offsets { }
175195public extension Snapshot {
176196
197+ //=------------------------------------------------------------------------=
198+ // MARK: Utilities
199+ //=------------------------------------------------------------------------=
200+
177201 @inlinable @inline ( __always) func distance< T> (
178202 from start: Index , to end: Index ) -> Offset < T > {
179203 T . distance ( from: start, to: end, in: self )
@@ -186,11 +210,15 @@ public extension Snapshot {
186210}
187211
188212//*============================================================================*
189- // MARK: * Encoding [...]
213+ // MARK: * Encoding
190214//*============================================================================*
191215
192216public protocol Encoding {
193217
218+ //=------------------------------------------------------------------------=
219+ // MARK: Utilities
220+ //=------------------------------------------------------------------------=
221+
194222 @inlinable @inline ( __always) static func distance(
195223 from start: String . Index , to end: String . Index ,
196224 in collection: some StringProtocol ) -> Offset < Self >
@@ -199,6 +227,10 @@ public protocol Encoding {
199227 from start: String . Index , move distance: Offset < Self > ,
200228 in collection: some StringProtocol ) -> String . Index
201229
230+ //=------------------------------------------------------------------------=
231+ // MARK: Utilities
232+ //=------------------------------------------------------------------------=
233+
202234 @inlinable @inline ( __always) static func distance(
203235 from start: Snapshot . Index , to end: Snapshot . Index ,
204236 in collection: Snapshot ) -> Offset < Self >
@@ -209,11 +241,15 @@ public protocol Encoding {
209241}
210242
211243//=----------------------------------------------------------------------------=
212- // MARK: + Details [...]
244+ // MARK: + Details
213245//=----------------------------------------------------------------------------=
214246
215247public extension Encoding {
216248
249+ //=------------------------------------------------------------------------=
250+ // MARK: Utilities
251+ //=------------------------------------------------------------------------=
252+
217253 @inlinable @inline ( __always) static func distance(
218254 from start: Snapshot . Index , to end: Snapshot . Index ,
219255 in collection: Snapshot ) -> Offset < Self > {
@@ -235,12 +271,16 @@ public extension Encoding {
235271}
236272
237273//*============================================================================*
238- // MARK: * Encoding x Character [...]
274+ // MARK: * Encoding x Character
239275//*============================================================================*
240276
241277extension Character : Encoding { }
242278public extension Character {
243279
280+ //=------------------------------------------------------------------------=
281+ // MARK: Utilities
282+ //=------------------------------------------------------------------------=
283+
244284 @inlinable @inline ( __always) static func distance(
245285 from start: String . Index , to end: String . Index ,
246286 in collection: some StringProtocol ) -> Offset < Self > {
@@ -253,6 +293,10 @@ public extension Character {
253293 collection. index ( start, offsetBy: Int ( distance) )
254294 }
255295
296+ //=------------------------------------------------------------------------=
297+ // MARK: Utilities
298+ //=------------------------------------------------------------------------=
299+
256300 @inlinable @inline ( __always) static func distance(
257301 from start: Snapshot . Index , to end: Snapshot . Index ,
258302 in collection: Snapshot ) -> Offset < Self > {
@@ -267,12 +311,16 @@ public extension Character {
267311}
268312
269313//*============================================================================*
270- // MARK: * Encoding x Unicode.Scalar [...]
314+ // MARK: * Encoding x Unicode.Scalar
271315//*============================================================================*
272316
273317extension Unicode . Scalar : Encoding { }
274318public extension Unicode . Scalar {
275319
320+ //=------------------------------------------------------------------------=
321+ // MARK: Utilities
322+ //=------------------------------------------------------------------------=
323+
276324 @inlinable @inline ( __always) static func distance(
277325 from start: String . Index , to end: String . Index ,
278326 in collection: some StringProtocol ) -> Offset < Self > {
@@ -287,12 +335,16 @@ public extension Unicode.Scalar {
287335}
288336
289337//*============================================================================*
290- // MARK: * Encoding x UTF16 [...]
338+ // MARK: * Encoding x UTF16
291339//*============================================================================*
292340
293341extension UTF16 : Encoding { }
294342public extension UTF16 {
295343
344+ //=------------------------------------------------------------------------=
345+ // MARK: Utilities
346+ //=------------------------------------------------------------------------=
347+
296348 @inlinable @inline ( __always) static func distance(
297349 from start: String . Index , to end: String . Index ,
298350 in collection: some StringProtocol ) -> Offset < Self > {
@@ -307,12 +359,16 @@ public extension UTF16 {
307359}
308360
309361//*============================================================================*
310- // MARK: * Encoding x UTF8 [...]
362+ // MARK: * Encoding x UTF8
311363//*============================================================================*
312364
313365extension UTF8 : Encoding { }
314366public extension UTF8 {
315367
368+ //=------------------------------------------------------------------------=
369+ // MARK: Utilities
370+ //=------------------------------------------------------------------------=
371+
316372 @inlinable @inline ( __always) static func distance(
317373 from start: String . Index , to end: String . Index ,
318374 in collection: some StringProtocol ) -> Offset < Self > {
0 commit comments