Skip to content

[SR-9955] String.Index.init?<S: StringProtocol>(_ sourcePosition: Swift.String.Index, within target: S) is missing #52358

@norio-nomura

Description

@norio-nomura
Previous ID SR-9955
Radar rdar://problem/32340799
Original Reporter @norio-nomura
Type New Feature
Status Resolved
Resolution Done
Environment

swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-17-a
swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels New Feature
Assignee @milseman
Priority Medium

md5: 6ba3b0d9475f51dabd794e1b6e524822

Issue Description:

That makes it impossible to write the code below.

extension StringProtocol where Index == String.Index, UTF16View.Index == String.Index {
    func toUTF16Indices(_ range: NSRange) -> Range<Index>? {
        precondition(range.location != NSNotFound)
        guard let start = utf16.index(utf16.startIndex, offsetBy: range.lowerBound, limitedBy: utf16.endIndex),
            let end = utf16.index(start, offsetBy: range.length, limitedBy: utf16.endIndex),
            let lowerBound = String.Index(start, within: self),
            let upperBound = String.Index(end, within: self)
            else { return nil }
        return Range(uncheckedBounds: (lower: lowerBound, upper: upperBound))
    }
}

Metadata

Metadata

Assignees

Labels

StringArea → standard library: The `String` typefeatureA feature request or implementationstandard libraryArea: Standard library umbrellaswift evolution implementedFlag → feature: A feature that was approved through the Swift evolution process and implemented

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions