[swift-evolution] Change Request: Make myString.hasPrefix("") and myString.hasSuffix("") return true

Xiaodi Wu xiaodi.wu at gmail.com
Wed Jul 20 15:21:12 CDT 2016


Doesn't your second argument undermine your first? If it's a trivial
solution and one rarely ever considers empty strings when invoking
`hasPrefix`, then returning the technically correct result must be a
trivial departure in behavior.


On Wed, Jul 20, 2016 at 15:14 Guillaume Lessard via swift-evolution <
swift-evolution at swift.org> wrote:

>
> > On 20 juil. 2016, at 12:42, Michael Peternell via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > +1
> > this should be a bugfix.
>
> First, NSString’s prefix function returns false for empty string
> parameters, and this would be a significant departure in behaviour.
>
> Second, while an empty string is technically a prefix to any other string,
> that is hardly ever an interesting answer; it is a trivial solution, just
> as y=0 is for y(x)=y’(x). It is easy to special-case if one really needs to
> consider the empty string.
>
> Cheers,
> Guillaume Lessard
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160720/2ad0404c/attachment.html>


More information about the swift-evolution mailing list