File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -131,10 +131,11 @@ extension UnsafeRawPointer {
131
131
_internalInvariant ( ( 0 ..< end) . contains ( i) )
132
132
_internalInvariant ( _isScalarAligned ( i) )
133
133
134
- // TODO: call internals instead
135
- let str = _str ( i..< end)
136
- let nextIdx = str. index ( after: str. startIndex)
137
- return i + str. utf8. distance ( from: str. startIndex, to: nextIdx)
134
+ return _nextGraphemeClusterBoundary ( startingAt: i) { idx in
135
+ guard idx < end else { return nil }
136
+ let ( scalar, end) = _decodeScalar ( startingAt: idx)
137
+ return ( scalar, end)
138
+ }
138
139
}
139
140
140
141
// @usableFromInline
@@ -144,10 +145,11 @@ extension UnsafeRawPointer {
144
145
) -> Int {
145
146
_internalInvariant ( _isScalarAligned ( i) )
146
147
147
- // TODO: call internals instead
148
- let str = _str ( 0 ..< i)
149
- let prevIdx = str. index ( before: str. endIndex)
150
- return str. utf8. distance ( from: str. startIndex, to: prevIdx)
148
+ return _previousGraphemeClusterBoundary ( endingAt: i) { idx in
149
+ guard idx > 0 else { return nil }
150
+ let ( scalar, prior) = _decodeScalar ( endingAt: idx)
151
+ return ( scalar, prior)
152
+ }
151
153
}
152
154
153
155
// @usableFromInline
You can’t perform that action at this time.
0 commit comments