Swift 4 String Manifesto
Dave Abrahams and Ben Cohen (mailing list):
The first step in improving this [internationalization] situation is to regularize all localized operations as invocations of normal string operations with extra parameters.
[…]
When assigning a
Substring
to a longer-lived variable (usually a stored property) explicitly of typeString
, a type conversion will be performed, and at this point the substring buffer is copied and the original string’s storage can be released.[…]
With
Substring
andString
being distinct types and sharing almost all interface and semantics, and with the highest-performance string processing requiring knowledge of encoding and layout that the currency types can’t provide, it becomes important to capture the common “string API” in a protocol. Since Unicode conformance is a key feature of string processing in Swift, we call that protocolUnicode
[…][…]
Index interchange between
String
and itsunicodeScalars
,codeUnits
, andextendedASCII
views can be made entirely seamless by having them share an index type (semantics of indexing aString
between grapheme cluster boundaries are TBD--it can either trap or be forgiving). Having a common index allows easy traversal into the interior of graphemes, something that is often needed, without making it likely that someone will do it by accident.[…]
In the long run, we should improve Swift string interpolation to the point where it can participate in most any formatting job. Mostly this centers around fixing the interpolation protocols per the previous item, and supporting localization.
[…]
This proposal depends on two new features in the Swift language:
Generic subscripts, to enable unified slicing syntax.
A subtype relationship between
Substring
andString
, enabling framework APIs to traffic solely inString
while still making it possible to avoid copies by handlingSubstring
s where necessary.
Regarding this last point, note that String
is a struct
.
I agree with Joe that Swift can learn a lot from Perl 6 grammar’s and we should take the time to do it right.
[…]
So why bless regex literals with language support at all? I see several reasons[…]
5 Comments RSS · Twitter
[…] Chris Lattner ATP Interview, Swift 4 String Manifesto, ABI Stability Deferred Until After Swift 3.0, Looking Back on Swift 3 and Ahead to Swift […]
[…] Swift 4: Synthesizing Equatable and Hashable Conformance, Swift 4: JSON With Encoder and Encodable, Swift 4 String Manifesto, Provide Custom Collections for Dictionary Keys and […]