[swift-evolution] Pitch: String Index Overhaul

Dave Abrahams dabrahams at apple.com
Tue May 30 16:48:46 CDT 2017


on Tue May 30 2017, Michael Ilseman <milseman-AT-apple.com> wrote:

>> On May 27, 2017, at 10:40 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> 
>> An index that does not fall on an exact boundary in a given `String`
>> or `Substring` view will be “rounded down” to the nearest boundary
>> when used for slicing or range replacement.  So, for example,
>> 
>
> What about normal subscript? I.e. what would the following print?
>
> print(s[s.unicodeScalars.indices.dropFirst().first!]) // “é”, or just
> the combining scalar?

I am proposing that it would be “é”

>
>
> Would unifying under the same type require that indices be less
> stateful than they currently are?

No; it's just a matter of unifying the states (in an enum).  You can
look at the implementation in https://github.com/apple/swift/pull/9806
for details.

>
>> ```swift
>> let s = "e\u{301}galite\u{301}"                          // "égalité"
>> print(s[s.unicodeScalars.indices.dropFirst().first!...]) // “égalité"
>> print(s[..<s.unicodeScalars.indices.last!])              // "égalit"
>> ```

-- 
-Dave


More information about the swift-evolution mailing list