where UnicodeScalarView.Element == Unicode.Scalar,
UnicodeScalarView.Index == Index
associatedtype SubSequence = Substring
var utf8: UTF8View { get }
var utf16: UTF16View { get }
var unicodeScalars: UnicodeScalarView { get }
func hasPrefix(_ prefix: String) -> Bool
func hasSuffix(_ suffix: String) -> Bool
func lowercased() -> String
func uppercased() -> String
/// Creates a string from the given Unicode code units in the specified
/// encoding.
///
/// - Parameters:
/// - codeUnits: A collection of code units encoded in the encoding
/// specified in `sourceEncoding`.
Why this protocol required method hasPrefix
has argument prefix
not suffix
?
Because its default implementation's argument name is suffix
, when I use this method with value of type String
, it appears hasPrefix(_ suffix: String)
.
However, when I use value of type some StringProtocol
, it's argument name is prefix
because protocol requirement uses prefix
.
Is there any reason? Or simply it is mistake of implementation?
2 Likes
eskimo
(Quinn “The Eskimo!”)
May 8, 2021, 9:58am
2
Or simply it is mistake of implementation?
Yeah, that looks like a copy’n’paste bug, and I recommend that you file it as such . Please post your bug number, just for the record.
Well spotted btw!
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
Thank you!
I created a PR about this a while back, but I didn't file this. Should I assign it myself?
apple:main
← ensan-hcl:rename_hasSuffix
opened 08:27AM - 08 May 21 UTC
[SR-14611](https://bugs.swift.org/browse/SR-14611)
https://github.com/apple… /swift/blob/7f4a1d5e20b4f43192d2cee9dd40a6869dba7f82/stdlib/public/core/StringProtocol.swift#L46
The argument of `hasSuffix` that `StringProtocol` requires is currently wrongly named. This PR replaces its name into `suffix` from `prefix`.
Because the argument is labeled as `_`, this is an internal change. It wouldn't affect anywhere.
I posted a question on the [forum](https://forums.swift.org/t/why-stringprotocol-hassuffix-has-argument-prefix/47976) just in case. I'm sorry if there is some purpose to name that `prefix`.
<!--
Before merging this pull request, you must run the Swift continuous integration tests.
For information about triggering CI builds via @swift-ci, see:
https://github.com/apple/swift/blob/master/docs/ContinuousIntegration.md#swift-ci
Thank you for your contribution to Swift!
-->
[EDIT] I did it.
opened 12:27PM - 08 May 21 UTC
closed 07:12AM - 09 May 21 UTC
bug
Standard Library
| | |
|------------------|-----------------|…
|Previous ID | SR-14611 |
|Radar | None |
|Original Reporter | ensan (JIRA User) |
|Type | Bug |
|Status | Closed |
|Resolution | Done |
<details>
<summary>Environment</summary>
Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
Target: x86_64-apple-darwin20.3.0
</details>
<details>
<summary>Additional Detail from JIRA</summary>
| | |
|------------------|-----------------|
|Votes | 0 |
|Component/s | Standard Library |
|Labels | Bug |
|Assignee | ensan (JIRA) |
|Priority | Medium |
md5: 6ee0dc96ce528d7b90a1423b9e29abc7
</details>
**Issue Description:**
The argument of hasSuffix that StringProtocol requires is currently wrongly named. It should be \`suffix\`.
<https://github.com/apple/swift/blob/main/stdlib/public/core/StringProtocol.swift#L46>