Skip to content

Updates for acceptance of SE-0180 [parallel merge required] #1105

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
Jul 11, 2017
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
6 changes: 3 additions & 3 deletions Foundation/ExtraStringAPIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ extension String.UTF16View.Index : Strideable {
/// Construct from an integer offset.
public init(_ offset: Int) {
_precondition(offset >= 0, "Negative UTF16 index offset not allowed")
self.init(_offset: offset)
self.init(encodedOffset: offset)
}

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

public func advanced(by n: Int) -> String.UTF16View.Index {
return String.UTF16View.Index(_offset.advanced(by: n))
return String.UTF16View.Index(encodedOffset.advanced(by: n))
}
}

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ extension NSRange {
where R.Bound == S.Index, S.Index == String.Index {
let r = region.relative(to: target)
self = NSRange(
location: r.lowerBound._utf16Index - target.startIndex._utf16Index,
length: r.upperBound._utf16Index - r.lowerBound._utf16Index
location: r.lowerBound.encodedOffset - target.startIndex.encodedOffset,
length: r.upperBound.encodedOffset - r.lowerBound.encodedOffset
)
}

Expand Down
15 changes: 6 additions & 9 deletions Foundation/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func _toNSArray<T, U : AnyObject>(_ a: [T], f: (T) -> U) -> NSArray {

func _toNSRange(_ r: Range<String.Index>) -> NSRange {
return NSRange(
location: r.lowerBound._utf16Index,
length: r.upperBound._utf16Index - r.lowerBound._utf16Index)
location: r.lowerBound.encodedOffset,
length: r.upperBound.encodedOffset - r.lowerBound.encodedOffset)
}

extension String {
Expand All @@ -47,10 +47,7 @@ extension String {
/// Return an `Index` corresponding to the given offset in our UTF-16
/// representation.
func _index(_ utf16Index: Int) -> Index {
return Index(
_base: String.UnicodeScalarView.Index(_position: utf16Index),
in: characters
)
return Index(encodedOffset: utf16Index)
}

/// Return a `Range<Index>` corresponding to the given `NSRange` of
Expand Down Expand Up @@ -1076,7 +1073,7 @@ extension String {
public
func rangeOfComposedCharacterSequence(at anIndex: Index) -> Range<Index> {
return _range(
_ns.rangeOfComposedCharacterSequence(at: anIndex._utf16Index))
_ns.rangeOfComposedCharacterSequence(at: anIndex.encodedOffset))
}

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

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

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

// - (NSString *)substringWithRange:(NSRange)aRange
Expand Down
4 changes: 2 additions & 2 deletions Foundation/URLComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public struct URLComponents : ReferenceConvertible, Hashable, Equatable, _Mutabl
private func _toStringRange(_ r : NSRange) -> Range<String.Index>? {
guard r.location != NSNotFound else { return nil }

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

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