[swift-users] range(of:options:range:locale:) with partial ranges
martinr448 at gmail.com
Tue Sep 26 02:09:34 CDT 2017
> On 22. Sep 2017, at 23:55, Ben Cohen <ben_cohen at apple.com> wrote:
> In order to be able to use pos… this function would need to be converted from it’s current signature (that takes a concrete Range) to be generic over any RangeExpression.In this case of this method, the range is optional – and in case of nil (which is the default) there would be insufficient context to determine the actual type of the RangeExpression. So we’d need to have an overload instead.
> But none of this ought to be necessary, because constant time slicing and index sharing means we don’t need to have functions take optional range arguments any more. Instead you can just write str[pos...].range(of: “f”).
That makes sense.
> Except... this technique has a bug in it for this particular method when used on substrings, that we need to fix before that can be used instead. Hoping for that to be fixed on master soon...
Good to know!
>> On Sep 21, 2017, at 2:44 AM, Martin R via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> The range(of:options:range:locale:) method of StringProtocol does not accept a partial range as search range. Example (Xcode 9, Swift 4):
>> let str = "foo"
>> let pos = str.startIndex
>> let r = str.range(of: "f", range: pos...)
>> // error: cannot convert value of type 'PartialRangeFrom<String.Index>'
>> // to expected argument type 'Range<String.Index>?'
>> Is that because it is an NSString method imported to Swift? Would it make sense to file an enhancement request?
>> Regards, Martin
>> swift-users mailing list
>> swift-users at swift.org <mailto:swift-users at swift.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users