Skip to content

Commit 9bf3854

Browse files
Dave Abrahamskevints
Dave Abrahams
authored andcommitted
1 parent 0b87e45 commit 9bf3854

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

Foundation/ExtraStringAPIs.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ extension String.UTF16View.Index : Strideable {
1717
/// Construct from an integer offset.
1818
public init(_ offset: Int) {
1919
_precondition(offset >= 0, "Negative UTF16 index offset not allowed")
20-
self.init(_offset: offset)
20+
self.init(encodedOffset: offset)
2121
}
2222

2323
public func distance(to other: String.UTF16View.Index) -> Int {
24-
return _offset.distance(to: other._offset)
24+
return encodedOffset.distance(to: other.encodedOffset)
2525
}
2626

2727
public func advanced(by n: Int) -> String.UTF16View.Index {
28-
return String.UTF16View.Index(_offset.advanced(by: n))
28+
return String.UTF16View.Index(encodedOffset.advanced(by: n))
2929
}
3030
}
3131

Foundation/NSRange.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ extension NSRange {
261261
where R.Bound == S.Index, S.Index == String.Index {
262262
let r = region.relative(to: target)
263263
self = NSRange(
264-
location: r.lowerBound._utf16Index - target.startIndex._utf16Index,
265-
length: r.upperBound._utf16Index - r.lowerBound._utf16Index
264+
location: r.lowerBound.encodedOffset - target.startIndex.encodedOffset,
265+
length: r.upperBound.encodedOffset - r.lowerBound.encodedOffset
266266
)
267267
}
268268

Foundation/NSStringAPI.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func _toNSArray<T, U : AnyObject>(_ a: [T], f: (T) -> U) -> NSArray {
3030

3131
func _toNSRange(_ r: Range<String.Index>) -> NSRange {
3232
return NSRange(
33-
location: r.lowerBound._utf16Index,
34-
length: r.upperBound._utf16Index - r.lowerBound._utf16Index)
33+
location: r.lowerBound.encodedOffset,
34+
length: r.upperBound.encodedOffset - r.lowerBound.encodedOffset)
3535
}
3636

3737
extension String {
@@ -47,10 +47,7 @@ extension String {
4747
/// Return an `Index` corresponding to the given offset in our UTF-16
4848
/// representation.
4949
func _index(_ utf16Index: Int) -> Index {
50-
return Index(
51-
_base: String.UnicodeScalarView.Index(_position: utf16Index),
52-
in: characters
53-
)
50+
return Index(encodedOffset: utf16Index)
5451
}
5552

5653
/// Return a `Range<Index>` corresponding to the given `NSRange` of
@@ -1076,7 +1073,7 @@ extension String {
10761073
public
10771074
func rangeOfComposedCharacterSequence(at anIndex: Index) -> Range<Index> {
10781075
return _range(
1079-
_ns.rangeOfComposedCharacterSequence(at: anIndex._utf16Index))
1076+
_ns.rangeOfComposedCharacterSequence(at: anIndex.encodedOffset))
10801077
}
10811078

10821079
// - (NSRange)rangeOfComposedCharacterSequencesForRange:(NSRange)range
@@ -1392,15 +1389,15 @@ extension String {
13921389
/// Returns a new string containing the characters of the
13931390
/// `String` from the one at a given index to the end.
13941391
public func substring(from index: Index) -> String {
1395-
return _ns.substring(from: index._utf16Index)
1392+
return _ns.substring(from: index.encodedOffset)
13961393
}
13971394

13981395
// - (NSString *)substringToIndex:(NSUInteger)anIndex
13991396

14001397
/// Returns a new string containing the characters of the
14011398
/// `String` up to, but not including, the one at a given index.
14021399
public func substring(to index: Index) -> String {
1403-
return _ns.substring(to: index._utf16Index)
1400+
return _ns.substring(to: index.encodedOffset)
14041401
}
14051402

14061403
// - (NSString *)substringWithRange:(NSRange)aRange

Foundation/URLComponents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ public struct URLComponents : ReferenceConvertible, Hashable, Equatable, _Mutabl
188188
private func _toStringRange(_ r : NSRange) -> Range<String.Index>? {
189189
guard r.location != NSNotFound else { return nil }
190190

191-
let utf16Start = String.UTF16View.Index(_offset: r.location)
192-
let utf16End = String.UTF16View.Index(_offset: r.location + r.length)
191+
let utf16Start = String.UTF16View.Index(encodedOffset: r.location)
192+
let utf16End = String.UTF16View.Index(encodedOffset: r.location + r.length)
193193

194194
guard let s = self.string else { return nil }
195195
guard let start = String.Index(utf16Start, within: s) else { return nil }

0 commit comments

Comments
 (0)