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

Closed
swift-ci opened this issue Jul 21, 2016 · 1 comment
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. feature A feature request or implementation standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

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 https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160718/024896.html.

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.

@swift-ci
Copy link
Collaborator Author

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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. feature A feature request or implementation standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant