[swift-users] range(of:options:range:locale:) with partial ranges
Ben Cohen
ben_cohen at apple.com
Fri Sep 22 16:55:14 CDT 2017
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”).
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...
> On Sep 21, 2017, at 2:44 AM, Martin R via swift-users <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
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170922/6a63f4fe/attachment.html>
More information about the swift-users
mailing list