[swift-evolution] Change Request: Make myString.hasPrefix("") and myString.hasSuffix("") return true&References=89F5D710-D05F-4FB2-BD08-1084C6ED8FCF at charliemonroe.net&In-reply-to=89F5D710-D05F-4FB2-BD08-1084C6ED8FCF at charliemonroe.net
me at tal.by
Mon Jul 18 16:51:22 CDT 2016
This almost seems more like a bug than a change request. Definitely agree.
> +1 - this shouldn't be hard to fix either - in StringLegacy.swift, add a
check for prefix.isEmpty and return true...
> > On Jul 18, 2016, at 7:36 PM, Chris Denter via swift-evolution<
swift-evolution at swift.org(mailto:swift-evolution at swift.org)>wrote:
> > Hello –
> > Currently, the standard library String functions .hasPrefix() and
.hasSuffix() will return false when given the empty string as input:
> > $ swift
> > 1>"".hasPrefix("")
> > $R0: Bool = false
> > 2>"foo".hasPrefix("")
> > $R1: Bool = false
> > 3>"foo".hasSuffix("")
> > $R2: Bool = false
> > This feels unexpected. The reason the methods behave this way seems to
bea leaked implementation detail(
> > Some languages, such as Python, return True in these cases -- perhaps
motivated by the `someSet.contains(emptySet) == true` analogy.
> > The ship has sailed for NSString and Foundation, but we might want to
bite the bullet and fix this for Swift before 3.0 makes that much harder.
> > Thank you so much for your time,
> > Chris_______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org(mailto:swift-evolution at swift.org)
> > https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution