Skip to content

[5.7] Rename String.Index _encodedOffset #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Sources/_StringProcessing/Unicode/Graphemes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ extension String {
startingAt index: Int,
nextScalar: (Int) -> (Unicode.Scalar, end: Int)
) -> Int {
_internalInvariant(index != endIndex._encodedOffset)
_internalInvariant(index != endIndex._encodedOffsetSP)
var state = _GraphemeBreakingState()
var index = index

while true {
let (scalar1, nextIdx) = nextScalar(index)
index = nextIdx

guard index != endIndex._encodedOffset else {
guard index != endIndex._encodedOffsetSP else {
break
}

Expand All @@ -254,15 +254,15 @@ extension String {
endingAt index: Int,
previousScalar: (Int) -> (Unicode.Scalar, start: Int)
) -> Int {
_internalInvariant(index != startIndex._encodedOffset)
_internalInvariant(index != startIndex._encodedOffsetSP)
var state = _GraphemeBreakingState()
var index = index

while true {
let (scalar2, previousIdx) = previousScalar(index)
index = previousIdx

guard index != startIndex._encodedOffset else {
guard index != startIndex._encodedOffsetSP else {
break
}

Expand Down Expand Up @@ -494,7 +494,7 @@ extension String {
// know that we are in an emoji sequence so our initial
// break question is answered as NO.
internal func checkIfInEmojiSequence(_ index: Int) -> Bool {
var emojiIdx = String.Index(_encodedOffset: index)
var emojiIdx = String.Index(_encodedOffsetSP: index)

guard emojiIdx != startIndex else {
return false
Expand Down Expand Up @@ -551,7 +551,7 @@ extension String {
// | = Is a linking consonant and we've seen a virama, so this is a
// legitimate indic sequence, so do NOT break the initial question.
internal func checkIfInIndicSequence(_ index: Int) -> Bool {
var indicIdx = String.Index(_encodedOffset: index)
var indicIdx = String.Index(_encodedOffsetSP: index)

guard indicIdx != startIndex else {
return false
Expand Down Expand Up @@ -639,7 +639,7 @@ extension String {
internal func countRIs(
_ index: Int
) -> Bool {
var riIdx = String.Index(_encodedOffset: index)
var riIdx = String.Index(_encodedOffsetSP: index)

guard riIdx != startIndex else {
return false
Expand Down
4 changes: 2 additions & 2 deletions Sources/_StringProcessing/Unicode/NecessaryEvils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ extension UTF16 {
}

extension String.Index {
internal var _encodedOffset: Int {
internal var _encodedOffsetSP: Int {
// The encoded offset is found in the top 48 bits.
Int(unsafeBitCast(self, to: UInt64.self) >> 16)
}

internal init(_encodedOffset offset: Int) {
internal init(_encodedOffsetSP offset: Int) {
self = unsafeBitCast(offset << 16, to: Self.self)
}
}