File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -340,7 +340,7 @@ extension _StringGuts {
340
340
/// correct value.
341
341
@_alwaysEmitIntoClient @inline ( __always)
342
342
internal func hasMatchingEncoding( _ i: String . Index ) -> Bool {
343
- isUTF8 ? i . _canBeUTF8 : i . _canBeUTF16
343
+ i . _hasMatchingEncoding ( isUTF8 : isUTF8 )
344
344
}
345
345
346
346
/// Return an index whose encoding can be assumed to match that of `self`.
Original file line number Diff line number Diff line change @@ -441,6 +441,20 @@ extension String.Index {
441
441
_encodingBits != Self . __utf8Bit
442
442
}
443
443
444
+ /// Returns true if the encoding of this index isn't known to be in conflict
445
+ /// with the specified encoding.
446
+ ///
447
+ /// If the index was created by code that was built on a stdlib below 5.7,
448
+ /// then this check may incorrectly return true on a mismatching index, but it
449
+ /// is guaranteed to never incorrectly return false. If all loaded binaries
450
+ /// were built in 5.7+, then this method is guaranteed to always return the
451
+ /// correct value.
452
+ @_alwaysEmitIntoClient // Swift 5.7
453
+ @inline ( __always)
454
+ internal func _hasMatchingEncoding( isUTF8 utf8: Bool ) -> Bool {
455
+ _encodingBits != Self . __encodingBit ( utf16: utf8)
456
+ }
457
+
444
458
/// Returns the same index with the UTF-8 bit set.
445
459
@_alwaysEmitIntoClient // Swift 5.7
446
460
@inline ( __always)
You can’t perform that action at this time.
0 commit comments