Skip to content

Commit 1b495b4

Browse files
committed
Merge pull request #2465 from apple/stdlib-add-unavailable-string-index-methods
stdlib: add unavailable methods on string indices (new indexing model migration)
2 parents 82d849e + de8fb07 commit 1b495b4

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

stdlib/public/core/StringUTF8.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ extension String {
134134
///
135135
/// - Precondition: The next value is representable.
136136
@warn_unused_result
137-
internal func successor() -> Index {
137+
internal func _successor() -> Index {
138138
// FIXME: swift-3-indexing-model: pull the following logic into UTF8View.index(after: Index)
139-
// FIXME: swift-3-indexing-model: remove the successor() function.
139+
// FIXME: swift-3-indexing-model: remove the _successor() function.
140140
let currentUnit = UTF8.CodeUnit(truncatingBitPattern: _buffer)
141141
let hiNibble = currentUnit >> 4
142142
// Map the high nibble of the current code unit into the
@@ -228,7 +228,7 @@ extension String {
228228
@warn_unused_result
229229
public func index(after i: Index) -> Index {
230230
// FIXME: swift-3-indexing-model: range check i?
231-
return i.successor()
231+
return i._successor()
232232
}
233233

234234
/// Access the element at `position`.

stdlib/public/core/UnavailableStringAPIs.swift.gyb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,43 @@ ${stringSubscriptComment}
109109
Builtin.unreachable()
110110
}
111111
}
112+
113+
% for View in ['UTF8View', 'UTF16View', 'UnicodeScalarView', 'CharacterView']:
114+
% Index = 'String.%s.Index' % View
115+
% Distance = 'String.%s.Index' % View
116+
extension ${Index} {
117+
@available(
118+
*, unavailable,
119+
message: "To get the next index call 'index(after:)' on the ${View} instance that produced the index.")
120+
public func successor() -> ${Index} {
121+
Builtin.unreachable()
122+
}
123+
% if View != 'UTF8View':
124+
@available(
125+
*, unavailable,
126+
message: "To get the previous index call 'index(before:)' on the ${View} instance that produced the index.")
127+
public func predecessor() -> ${Index} {
128+
Builtin.unreachable()
129+
}
130+
% end
131+
@available(
132+
*, unavailable,
133+
message: "To advance an index by n steps call 'index(_:offsetBy:)' on the ${View} instance that produced the index.")
134+
public func advancedBy(n: ${Distance}) -> ${Index} {
135+
Builtin.unreachable()
136+
}
137+
@available(
138+
*, unavailable,
139+
message: "To advance an index by n steps stopping at a given limit call 'index(_:offsetBy:limitedBy:)' on ${View} instance that produced the index. Note that the Swift 3 API returns 'nil' when trying to advance past the limit; the Swift 2 API returned the limit.")
140+
public func advancedBy(n: ${Distance}, limit: ${Index}) -> ${Index} {
141+
Builtin.unreachable()
142+
}
143+
@available(
144+
*, unavailable,
145+
message: "To find the distance between two indices call 'distance(from:to:)' on the ${View} instance that produced the index.")
146+
public func distanceTo(end: ${Index}) -> ${Distance} {
147+
Builtin.unreachable()
148+
}
149+
}
150+
% end
151+

0 commit comments

Comments
 (0)