Skip to content

Commit 17036b4

Browse files
committed
Merge pull request #2569 from moiseev/character-index
2 parents 2fb823e + 9baaccd commit 17036b4

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

stdlib/public/core/StringCharacterView.swift

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,6 @@ extension String.CharacterView : BidirectionalCollection {
9393
self._countUTF16 = _countUTF16
9494
}
9595

96-
/// Returns the next consecutive value after `self`.
97-
///
98-
/// - Precondition: The next value is representable.
99-
// FIXME: swift-3-indexing-model: pull the following logic into UTF8View.index(after: Index)
100-
internal func _successor() -> Index {
101-
_precondition(_base != _base._viewEndIndex, "cannot increment endIndex")
102-
return Index(_base: _endBase)
103-
}
104-
105-
/// Returns the previous consecutive value before `self`.
106-
///
107-
/// - Precondition: The previous value is representable.
108-
// FIXME: swift-3-indexing-model: pull the following logic into UTF8View.index(before: Index)
109-
internal func _predecessor() -> Index {
110-
_precondition(_base != _base._viewStartIndex,
111-
"cannot decrement startIndex")
112-
let predecessorLengthUTF16 =
113-
Index._measureExtendedGraphemeClusterBackward(from: _base)
114-
return Index(
115-
_base: UnicodeScalarView.Index(
116-
_utf16Index - predecessorLengthUTF16, _base._core))
117-
}
118-
11996
internal let _base: UnicodeScalarView.Index
12097

12198
/// The count of this extended grapheme cluster in UTF-16 code units.
@@ -238,17 +215,28 @@ extension String.CharacterView : BidirectionalCollection {
238215
return Index(_base: unicodeScalars.endIndex)
239216
}
240217

241-
// TODO: swift-3-indexing-model - add docs
218+
/// Returns the next consecutive position after `i`.
219+
///
220+
/// - Precondition: The next position is valid.
242221
@warn_unused_result
243222
public func index(after i: Index) -> Index {
244-
// FIXME: swift-3-indexing-model: range check i?
245-
return i._successor()
223+
_precondition(i._base != i._base._viewEndIndex, "cannot increment endIndex")
224+
return Index(_base: i._endBase)
246225
}
247226

248-
// TODO: swift-3-indexing-model - add docs
227+
/// Returns the previous consecutive position before `i`.
228+
///
229+
/// - Precondition: The previous position is valid.
249230
@warn_unused_result
250231
public func index(before i: Index) -> Index {
251-
return i._predecessor()
232+
// FIXME: swift-3-indexing-model: range check i?
233+
_precondition(i._base != i._base._viewStartIndex,
234+
"cannot decrement startIndex")
235+
let predecessorLengthUTF16 =
236+
Index._measureExtendedGraphemeClusterBackward(from: i._base)
237+
return Index(
238+
_base: UnicodeScalarView.Index(
239+
i._utf16Index - predecessorLengthUTF16, i._base._core))
252240
}
253241

254242
/// Access the `Character` at `position`.

0 commit comments

Comments
 (0)