<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">+1 - this shouldn't be hard to fix either - in StringLegacy.swift, add a check for prefix.isEmpty and return true...<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 18, 2016, at 7:36 PM, Chris Denter via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello –<div class=""><br class=""></div><div class="">Currently, the standard library String functions .hasPrefix() and .hasSuffix() will return false when given the empty string as input:</div><div class=""><br class=""></div><div class=""><div class="">$ swift</div><div class="">&nbsp; 1&gt; "".hasPrefix("")</div><div class="">$R0: Bool = false</div><div class="">&nbsp; 2&gt; "foo".hasPrefix("")&nbsp;</div><div class="">$R1: Bool = false</div><div class="">&nbsp; 3&gt; "foo".hasSuffix("")</div><div class="">$R2: Bool = false</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">This feels unexpected. The reason the methods behave this way seems to be <a href="https://twitter.com/cdntr/status/755059959713427456" target="_blank" class="">a leaked implementation detail</a>.</div><div class="">Some languages, such as Python, return True in these cases -- perhaps motivated by the `someSet.contains(emptySet) == true` analogy.</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Thank you so much for your time,</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; Chris</div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>