Revert "[stdlib] String index interchange, etc." (#10812)

rdar://33186295
This commit is contained in:
Xi Ge
2017-07-07 12:03:16 -07:00
committed by GitHub
parent 0a483187b1
commit d9fb110674
27 changed files with 1414 additions and 911 deletions

View File

@@ -32,8 +32,8 @@ func _toNSArray<T, U : AnyObject>(_ a: [T], f: (T) -> U) -> NSArray {
func _toNSRange(_ r: Range<String.Index>) -> NSRange {
return NSRange(
location: r.lowerBound.encodedOffset,
length: r.upperBound.encodedOffset - r.lowerBound.encodedOffset)
location: r.lowerBound._utf16Index,
length: r.upperBound._utf16Index - r.lowerBound._utf16Index)
}
// We only need this for UnsafeMutablePointer, but there's not currently a way
@@ -72,7 +72,10 @@ extension String {
/// Return an `Index` corresponding to the given offset in our UTF-16
/// representation.
func _index(_ utf16Index: Int) -> Index {
return Index(encodedOffset: utf16Index)
return Index(
_base: String.UnicodeScalarView.Index(_position: utf16Index),
in: characters
)
}
/// Return a `Range<Index>` corresponding to the given `NSRange` of
@@ -1257,7 +1260,7 @@ extension String {
public
func rangeOfComposedCharacterSequence(at anIndex: Index) -> Range<Index> {
return _range(
_ns.rangeOfComposedCharacterSequence(at: anIndex.encodedOffset))
_ns.rangeOfComposedCharacterSequence(at: anIndex._utf16Index))
}
// - (NSRange)rangeOfComposedCharacterSequencesForRange:(NSRange)range
@@ -1607,7 +1610,7 @@ 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.encodedOffset)
return _ns.substring(from: index._utf16Index)
}
// - (NSString *)substringToIndex:(NSUInteger)anIndex
@@ -1615,7 +1618,7 @@ extension String {
/// 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.encodedOffset)
return _ns.substring(to: index._utf16Index)
}
// - (NSString *)substringWithRange:(NSRange)aRange