[swift-evolution] Change Request: Make myString.hasPrefix("") and myString.hasSuffix("") return true
allevato at google.com
Wed Jul 20 15:21:03 CDT 2016
On Wed, Jul 20, 2016 at 1:14 PM 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.
It would be a significant correction in behavior.
> 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.
On the contrary—I've written code in the past that expected this behavior
(because why wouldn't I? It's the correct behavior) and was quite surprised
when NSString's behavior resulted in a bug.
NSString being plain wrong here should not consign us to wrongness forever.
Every other mainstream language I use day-to-day implements this correctly,
and so should Swift.
> Guillaume Lessard
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution