|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See https://swift.org/LICENSE.txt for license information
|
9 | 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 |
| -%{ |
14 |
| -stringSubscriptComment = """ |
| 13 | +extension String { |
15 | 14 | /// Subscripting strings with integers is not available.
|
16 | 15 | ///
|
17 | 16 | /// The concept of "the `i`th character in a string" has
|
@@ -48,28 +47,57 @@ stringSubscriptComment = """
|
48 | 47 | /// Unicode algorithms instead, for example,
|
49 | 48 | /// `String.localizedStandardCompare()`,
|
50 | 49 | /// `String.localizedLowercaseString`,
|
51 |
| - /// `String.localizedStandardRangeOfString()` etc.""" |
52 |
| -}% |
53 |
| - |
54 |
| -extension String { |
55 |
| -${stringSubscriptComment} |
| 50 | + /// `String.localizedStandardRangeOfString()` etc. |
56 | 51 | @available(
|
57 | 52 | *, 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 | + ) |
59 | 55 | public subscript(i: Int) -> Character {
|
60 | 56 | Builtin.unreachable()
|
61 | 57 | }
|
62 | 58 |
|
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. |
64 | 96 | @available(
|
65 | 97 | *, 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 | + ) |
67 | 100 | public subscript<R: RangeExpression>(bounds: R) -> String where R.Bound == Int {
|
68 | 101 | Builtin.unreachable()
|
69 | 102 | }
|
70 | 103 | }
|
71 |
| - |
72 |
| - |
73 |
| -// ${'Local Variables'}: |
74 |
| -// eval: (read-only-mode 1) |
75 |
| -// End: |
|
0 commit comments