Skip to content

Commit 0c4aa60

Browse files
committed
de-gyb unavailablestringapis
1 parent 3f5c716 commit 0c4aa60

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ set(SWIFTLIB_ESSENTIAL
168168
SwiftNativeNSArray.swift
169169
ThreadLocalStorage.swift
170170
UIntBuffer.swift
171+
UnavailableStringAPIs.swift
171172
UnicodeEncoding.swift
172173
UnicodeHelpers.swift
173174
UnicodeParser.swift
@@ -193,7 +194,6 @@ set(SWIFTLIB_ESSENTIAL_GYB_SOURCES
193194
FloatingPointParsing.swift.gyb
194195
FloatingPointTypes.swift.gyb
195196
IntegerTypes.swift.gyb
196-
UnavailableStringAPIs.swift.gyb
197197
UnsafeBufferPointer.swift.gyb
198198
UnsafeRawBufferPointer.swift.gyb
199199
)

stdlib/public/core/UnavailableStringAPIs.swift.gyb renamed to stdlib/public/core/UnavailableStringAPIs.swift

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
%{
14-
stringSubscriptComment = """
13+
extension String {
1514
/// Subscripting strings with integers is not available.
1615
///
1716
/// The concept of "the `i`th character in a string" has
@@ -48,28 +47,57 @@ stringSubscriptComment = """
4847
/// Unicode algorithms instead, for example,
4948
/// `String.localizedStandardCompare()`,
5049
/// `String.localizedLowercaseString`,
51-
/// `String.localizedStandardRangeOfString()` etc."""
52-
}%
53-
54-
extension String {
55-
${stringSubscriptComment}
50+
/// `String.localizedStandardRangeOfString()` etc.
5651
@available(
5752
*, unavailable,
58-
message: "cannot subscript String with an Int, use a String.Index instead.")
53+
message: "cannot subscript String with an Int, use a String.Index instead."
54+
)
5955
public subscript(i: Int) -> Character {
6056
Builtin.unreachable()
6157
}
6258

63-
${stringSubscriptComment}
59+
/// Subscripting strings with integers is not available.
60+
///
61+
/// The concept of "the `i`th character in a string" has
62+
/// different interpretations in different libraries and system
63+
/// components. The correct interpretation should be selected
64+
/// according to the use case and the APIs involved, so `String`
65+
/// cannot be subscripted with an integer.
66+
///
67+
/// Swift provides several different ways to access the character
68+
/// data stored inside strings.
69+
///
70+
/// - `String.utf8` is a collection of UTF-8 code units in the
71+
/// string. Use this API when converting the string to UTF-8.
72+
/// Most POSIX APIs process strings in terms of UTF-8 code units.
73+
///
74+
/// - `String.utf16` is a collection of UTF-16 code units in
75+
/// string. Most Cocoa and Cocoa touch APIs process strings in
76+
/// terms of UTF-16 code units. For example, instances of
77+
/// `NSRange` used with `NSAttributedString` and
78+
/// `NSRegularExpression` store substring offsets and lengths in
79+
/// terms of UTF-16 code units.
80+
///
81+
/// - `String.unicodeScalars` is a collection of Unicode scalars.
82+
/// Use this API when you are performing low-level manipulation
83+
/// of character data.
84+
///
85+
/// - `String.characters` is a collection of extended grapheme
86+
/// clusters, which are an approximation of user-perceived
87+
/// characters.
88+
///
89+
/// Note that when processing strings that contain human-readable
90+
/// text, character-by-character processing should be avoided to
91+
/// the largest extent possible. Use high-level locale-sensitive
92+
/// Unicode algorithms instead, for example,
93+
/// `String.localizedStandardCompare()`,
94+
/// `String.localizedLowercaseString`,
95+
/// `String.localizedStandardRangeOfString()` etc.
6496
@available(
6597
*, unavailable,
66-
message: "cannot subscript String with an integer range, use a String.Index range instead.")
98+
message: "cannot subscript String with an integer range, use a String.Index range instead."
99+
)
67100
public subscript<R: RangeExpression>(bounds: R) -> String where R.Bound == Int {
68101
Builtin.unreachable()
69102
}
70103
}
71-
72-
73-
// ${'Local Variables'}:
74-
// eval: (read-only-mode 1)
75-
// End:

0 commit comments

Comments
 (0)