[stdlib] String is no longer a SequenceType

<rdar://20494686>

String itsef should only expose Unicode-correct algorithms, like proper
substring/prefix/suffix search, enumerating words/lines/paragraphs, case
folding etc. Promoting sequence-centric algorithms to methods on String
is not acceptable since it invites users to write wrong code. Thus,
String has to lose its SequenceType conformance.

Nevertheless, we recognize that sometimes it is useful to manipulate the
String contents on lower levels (UTF-8, UTF-16, Unicode scalars,
extended grapheme clusters), for example, when implementing high-level
Unicode operations, so we can't remove low-level operations
altogether. For this reason, String provides nested "views" for the
first three low-level representations, but grapheme clusters were in a
privileged position -- String itself is a collection of grapheme
clusters. We propose to add a characters view that will represent the
String as a collection of Character values.

Swift SVN r28065
This commit is contained in:
Dave Abrahams
2015-05-02 01:52:02 +00:00
parent 54519ea896
commit 4ce1891cae
11 changed files with 243 additions and 33 deletions

View File

@@ -252,7 +252,9 @@ public struct EnumerateSequence<Base : SequenceType> : SequenceType {
/// *n*s are consecutive `Int`s starting at zero, and *x*s are
/// the elements of `base`:
///
/// > for (n, c) in enumerate("Swift") { println("\(n): '\(c)'" )}
/// > for (n, c) in enumerate("Swift".characters) {
/// println("\(n): '\(c)'" )
/// }
/// 0: 'S'
/// 1: 'w'
/// 2: 'i'