Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-2131] The empty string is not a prefix/suffix of itself (or any string) #44739

swift-ci opened this issue Jul 21, 2016 · 1 comment


Copy link

swift-ci commented Jul 21, 2016

Previous ID SR-2131
Radar None
Original Reporter abl (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, LanguageFeatureRequest
Assignee abl (JIRA)
Priority Medium

md5: d4b6fd317e1bd24e83fe8dec7117f5da

Issue Description:

Inspired by

Currently, the empty string has unique prefix/suffix behavior compared to other strings:

let E = ""
let a = "a"  // any non-empty string
let b = "b"  // any non-empty string

a == a  // true
a.hasPrefix(a)  // true
a.hasSuffix(a)  // true
(a+b).hasSuffix(b)  // true
(b+a).hasPrefix(b)  // true

E == E  // true
E.hasPrefix(E)  // false
E.hasSuffix(E)  // false
(a+E).hasSuffix(E)  // false
(E+a).hasPrefix(E)  // false

This is consistent with NSString and Foundation but conflicts with other languages and with concatenation - for all non-empty strings a and b, (a+b) has a prefix of a and a suffix of b.

Copy link
Collaborator Author

swift-ci commented Jul 23, 2016

Comment by Alexander Lash (JIRA)

Resolved in #3651

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant