[swift-evolution] Change Request: Make myString.hasPrefix("") and myString.hasSuffix("") return true
dabrahams at apple.com
Wed Jul 20 14:56:52 CDT 2016
on Wed Jul 20 2016, Michael Peternell <swift-evolution at swift.org> wrote:
> this should be a bugfix.
PRs for bugfixes always appreciated.
>> Am 18.07.2016 um 19:36 schrieb Chris Denter via swift-evolution <swift-evolution at swift.org>:
>> 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 be a 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,
>> swift-evolution mailing list
>> swift-evolution at swift.org
> swift-evolution mailing list
> swift-evolution at swift.org
More information about the swift-evolution