improve and clean up StringXxxx (note a couple compile errors remain in dependent files)

This commit is contained in:
Shawn Erickson
2016-03-08 15:04:45 -08:00
parent 80670a2b24
commit 7a84232a06
4 changed files with 78 additions and 49 deletions

View File

@@ -93,14 +93,19 @@ extension String.CharacterView : BidirectionalCollection {
/// Returns the next consecutive value after `self`.
///
/// - Precondition: The next value is representable.
// FIXME: swift-3-indexing-model: pull the following logic into UTF8View.next(Index)
/*
public func successor() -> Index {
_precondition(_base != _base._viewEndIndex, "cannot increment endIndex")
return Index(_base: _endBase)
}
*/
/// Returns the previous consecutive value before `self`.
///
/// - Precondition: The previous value is representable.
// FIXME: swift-3-indexing-model: pull the following logic into UTF8View.previous(Index)
/*
public func predecessor() -> Index {
_precondition(_base != _base._viewStartIndex,
"cannot decrement startIndex")
@@ -110,6 +115,7 @@ extension String.CharacterView : BidirectionalCollection {
_base: UnicodeScalarView.Index(
_utf16Index - predecessorLengthUTF16, _base._core))
}
*/
internal let _base: UnicodeScalarView.Index
@@ -216,6 +222,8 @@ extension String.CharacterView : BidirectionalCollection {
}
}
public typealias IndexDistance = Int
/// The position of the first `Character` if `self` is
/// non-empty; identical to `endIndex` otherwise.
public var startIndex: Index {
@@ -234,12 +242,35 @@ extension String.CharacterView : BidirectionalCollection {
// TODO: swift-3-indexing-model - add docs
@warn_unused_result
public func next(i: Index) -> Index {
// FIXME: swift-3-indexing-model: range check i?
fatalError("FIXME: swift-3-indexing-model implement")
}
// TODO: swift-3-indexing-model - add docs
@warn_unused_result
public func previous(i: Index) -> Index {
// FIXME: swift-3-indexing-model: range check i?
fatalError("FIXME: swift-3-indexing-model implement")
}
// TODO: swift-3-indexing-model - add docs
@warn_unused_result
public func advance(i: Index, by n: IndexDistance) -> Index {
// FIXME: swift-3-indexing-model: range check i?
fatalError("FIXME: swift-3-indexing-model implement")
}
// TODO: swift-3-indexing-model - add docs
@warn_unused_result
public func advance(i: Index, by n: IndexDistance, limit: Index) -> Index {
// FIXME: swift-3-indexing-model: range check i?
fatalError("FIXME: swift-3-indexing-model implement")
}
// TODO: swift-3-indexing-model - add docs
@warn_unused_result
public func distance(from start: Index, to end: Index) -> IndexDistance {
// FIXME: swift-3-indexing-model: range check start and end?
fatalError("FIXME: swift-3-indexing-model implement")
}