@@ -140,22 +140,20 @@ extension NSRange {
140
140
//===----------------------------------------------------------------------===//
141
141
142
142
extension NSRange {
143
- public init < R: RangeExpression > ( _ rangeExpression : R )
143
+ public init < R: RangeExpression > ( _ region : R )
144
144
where R. Bound: FixedWidthInteger , R. Bound. Stride : SignedInteger {
145
- let range = rangeExpression. relative ( to: 0 ..< R . Bound. max)
146
- let start : Int = numericCast ( range. lowerBound)
147
- let end : Int = numericCast ( range. upperBound)
148
- self = NSRange ( location: start, length: end - start)
145
+ let r = region. relative ( to: 0 ..< R . Bound. max)
146
+ location = numericCast ( r. lowerBound)
147
+ length = numericCast ( r. count)
149
148
}
150
149
151
- public init < R: RangeExpression , S: StringProtocol > ( _ rangeExpression: R , in string: S )
152
- where R. Bound == String . Index , S. Index == String . Index {
153
- let range = rangeExpression. relative ( to: string)
154
- let start = range. lowerBound. samePosition ( in: string. utf16)
155
- let end = range. upperBound. samePosition ( in: string. utf16)
156
- let location = string. utf16. distance ( from: string. utf16. startIndex, to: start)
157
- let length = string. utf16. distance ( from: start, to: end)
158
- self = NSRange ( location: location, length: length)
150
+ public init < R: RangeExpression , S: StringProtocol > ( _ region: R , in target: S )
151
+ where R. Bound == S . Index , S. Index == String . Index {
152
+ let r = region. relative ( to: target)
153
+ self = NSRange (
154
+ location: r. lowerBound. _utf16Index - target. startIndex. _utf16Index,
155
+ length: r. upperBound. _utf16Index - r. lowerBound. _utf16Index
156
+ )
159
157
}
160
158
161
159
@available ( swift, deprecated: 4 , renamed: " Range.init(_:) " )
0 commit comments