@@ -174,10 +174,10 @@ extension String {
174
174
175
175
init ( _ _core: _StringCore ) {
176
176
self . _core = _core
177
- self . _endIndex = Index ( _core , _core. endIndex, Index . _emptyBuffer)
177
+ self . _endIndex = Index ( _coreIndex : _core. endIndex, Index . _emptyBuffer)
178
178
if _fastPath ( _core. count != 0 ) {
179
179
let ( _, buffer) = _core. _encodeSomeUTF8 ( from: 0 )
180
- self . _startIndex = Index ( _core , 0 , buffer)
180
+ self . _startIndex = Index ( _coreIndex : 0 , buffer)
181
181
} else {
182
182
self . _startIndex = self . _endIndex
183
183
}
@@ -208,27 +208,23 @@ extension String {
208
208
public struct Index : Comparable {
209
209
internal typealias Buffer = _StringCore . _UTF8Chunk
210
210
211
- init ( _ _core: _StringCore , _ _coreIndex: Int ,
212
- _ _buffer: Buffer ) {
213
- self . _core = _core
211
+ init ( _coreIndex: Int , _ _buffer: Buffer ) {
214
212
self . _coreIndex = _coreIndex
215
213
self . _buffer = _buffer
216
- _sanityCheck ( _coreIndex >= 0 )
217
- _sanityCheck ( _coreIndex <= _core. count)
218
214
}
219
215
220
216
/// True iff the index is at the end of its view or if the next
221
217
/// byte begins a new UnicodeScalar.
222
- internal var _isOnUnicodeScalarBoundary : Bool {
218
+ internal func _isOnUnicodeScalarBoundary( in core : _StringCore ) -> Bool {
223
219
let buffer = UInt32 ( truncatingBitPattern: _buffer)
224
220
let ( codePoint, _) = UTF8 . _decodeOne ( buffer)
225
- return codePoint != nil || _isAtEnd
221
+ return codePoint != nil || _isEndIndex ( of : core )
226
222
}
227
223
228
224
/// True iff the index is at the end of its view
229
- internal var _isAtEnd : Bool {
225
+ internal func _isEndIndex ( of core : _StringCore ) -> Bool {
230
226
return _buffer == Index . _emptyBuffer
231
- && _coreIndex == _core . endIndex
227
+ && _coreIndex == core . endIndex
232
228
}
233
229
234
230
/// The value of the buffer when it is empty
@@ -247,13 +243,12 @@ extension String {
247
243
return ( thisBuffer >> 8 ) | _bufferHiByte
248
244
}
249
245
250
- /// The underlying buffer we're presenting as UTF-8
251
- internal let _core : _StringCore
252
246
/// The position of `self`, rounded up to the nearest unicode
253
247
/// scalar boundary, in the underlying UTF-16.
254
248
internal let _coreIndex : Int
255
- /// If `self` is at the end of its `_core`, has the value `_endBuffer`.
256
- /// Otherwise, the low byte contains the value of
249
+ /// If `self` is at the end of its `_core`, has the value `_emptyBuffer`.
250
+ /// Otherwise, the low byte contains the value of the UTF-8 code unit
251
+ /// at this position.
257
252
internal let _buffer : Buffer
258
253
}
259
254
@@ -292,21 +287,21 @@ extension String {
292
287
let nextCoreIndex = i. _coreIndex &+ increment
293
288
let nextBuffer = Index . _nextBuffer ( after: i. _buffer)
294
289
295
- // if the nextBuffer is nonempty, we have all we need
290
+ // If the nextBuffer is nonempty, we have all we need
296
291
if _fastPath ( nextBuffer != Index . _emptyBuffer) {
297
- return Index ( i . _core , nextCoreIndex, nextBuffer)
292
+ return Index ( _coreIndex : nextCoreIndex, nextBuffer)
298
293
}
299
294
// If the underlying UTF16 isn't exhausted, fill a new buffer
300
- else if _fastPath ( nextCoreIndex < i . _core. endIndex) {
301
- let ( _, freshBuffer) = i . _core. _encodeSomeUTF8 ( from: nextCoreIndex)
302
- return Index ( _core , nextCoreIndex, freshBuffer)
295
+ else if _fastPath ( nextCoreIndex < _core. endIndex) {
296
+ let ( _, freshBuffer) = _core. _encodeSomeUTF8 ( from: nextCoreIndex)
297
+ return Index ( _coreIndex : nextCoreIndex, freshBuffer)
303
298
}
304
299
else {
305
300
// Produce the endIndex
306
301
_precondition (
307
- nextCoreIndex == i . _core. endIndex,
302
+ nextCoreIndex == _core. endIndex,
308
303
" Can't increment past endIndex of String.UTF8View " )
309
- return Index ( _core , nextCoreIndex, nextBuffer)
304
+ return Index ( _coreIndex : nextCoreIndex, nextBuffer)
310
305
}
311
306
}
312
307
@@ -478,7 +473,7 @@ public func < (
478
473
extension String . UTF8View . Index {
479
474
internal init ( _ core: _StringCore , _utf16Offset: Int ) {
480
475
let ( _, buffer) = core. _encodeSomeUTF8 ( from: _utf16Offset)
481
- self . init ( core , _utf16Offset, buffer)
476
+ self . init ( _coreIndex : _utf16Offset, buffer)
482
477
}
483
478
484
479
/// Creates an index in the given UTF-8 view that corresponds exactly to the
0 commit comments