[stdlib] Silence deprecation warnings about CharacterView in stdlib

- Rename `Substring.CharacterView` to `Substring._CharacterView`, adding a deprecated typealias for the original name, like we do for `String.CharacterView`.
- Add a non-deprecated `Substring._characters` property, emulating `String.characters`.
- Explicitly deprecate the following members:
    * String.withMutableCharacters<R>(_: (inout CharacterView) -> R) -> R
    * String.subscript(Range<Index>) -> String.CharacterView
    * Substring._CharacterView.subscript(Range<Index>) -> Substring.CharacterView
    * Substring.init(_: CharacterView)
    * String.init(_: Substring.CharacterView)
This commit is contained in:
Karoy Lorentey
2018-01-24 21:16:48 +00:00
parent 92a2f9cb8f
commit e6afe829a1
2 changed files with 43 additions and 14 deletions

View File

@@ -140,6 +140,8 @@ extension String {
/// argument is valid only for the duration of the closure's execution.
/// - Returns: The return value, if any, of the `body` closure parameter.
@_inlineable // FIXME(sil-serialize-all)
@available(swift, deprecated: 3.2, message:
"Please mutate String or Substring directly")
public mutating func withMutableCharacters<R>(
_ body: (inout CharacterView) -> R
) -> R {
@@ -374,6 +376,8 @@ extension String._CharacterView {
/// - Complexity: O(*n*) if the underlying string is bridged from
/// Objective-C, where *n* is the length of the string; otherwise, O(1).
@_inlineable // FIXME(sil-serialize-all)
@available(swift, deprecated: 3.2, message:
"Please use String or Substring directly")
public subscript(bounds: Range<Index>) -> String.CharacterView {
let offsetRange: Range<Int> =
_toBaseIndex(bounds.lowerBound).encodedOffset ..<