-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0089] [in progress] Rename string reflection init #3212
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
Conversation
Thank you for working on this! I'm not actually sure if var s = "a\u{0301}"
String(s.utf8[s.utf8.index(s.utf8.startIndex, offsetBy: 2)..<s.utf8.endIndex]) // nil |
No, it shouldn't be implemented for those types. There should be explicit separate constructors for lossless one-way conversions. |
public init?(_ description: String) { | ||
if let v = UInt32(description) where (v < 0xD800 || v > 0xDFFF) | ||
&& v <= 0x10FFFF { | ||
self = UnicodeScalar(v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the intent of the LosslessStringConvertible
protocol is that T(String(someInstanceOfT)) == someInstanceOfT
. That is, this initializer should parse back what String
initializer returns.
(swift) var c: UnicodeScalar = "a"
// c : UnicodeScalar = "a"
(swift) c.description
// r0 : String = "\"a\""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still relevant.
@frootloops For For extension String.CharacterView : LosslessStringConvertible {
public init?(_ description: String) {
self = description.characters
}
} |
It's quite possible that All existing As for |
@@ -259,7 +259,7 @@ public struct StaticString | |||
|
|||
extension StaticString { | |||
public var customMirror: Mirror { | |||
return Mirror(reflecting: String(self)) | |||
return Mirror(reflecting: String(describing: self)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, as a strength reduction, we can directly query .description
, since we are in the same type:
return Mirror(reflecting: description)
Superseded by #3574. |
Hello @gribozavr
I just started work on the proposal and if you could please help me with it. Because I don't really understand how to implement
LosslessStringConvertible
protocol forString.*
(String.UTF8View
,String.UTF16View.
..) and forFloatingPoint
andInteger
.Thanks for any help :)