-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New FP Parsing: Use relevant part of a substring #86018
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
base: main
Are you sure you want to change the base?
Conversation
|
@milseman I would appreciate if someone could double-check my use of internal String APIs here. In particular, I've not made any effort to test cases where a string is not "fast UTF8" capable; advice appreciated. |
|
This is a follow-on to #85797 |
| } else { | ||
| // Otherwise, make a copy so we have contiguous UTF8... | ||
| let string = String(text) | ||
| parsed = unsafe string._guts.withFastUTF8 { chars -> ${Self}? in |
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.
In particular, can I reliably assume that a copied string will always support withFastUTF8?
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.
Why not just use https://developer.apple.com/documentation/swift/string/makecontiguousutf8() ?
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.
The current implementation does always produce a string that supports withFastUTF8, but we might as well be sure and call makeContiguousUTF8(). I would suggest withUTF8, since it is a wrapper for makeContiguousUTF8() followed by _guts.withFastUTF8…
| expectNotNil(parsed) | ||
| expectEqual(parsed!.bitPattern, (2.0).bitPattern) | ||
| } | ||
|
|
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.
Do I need to test bridged strings specially here?
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'm not going to turn down free test coverage of my code if it's offered, but I don't think it's at all necessary.
|
@swift-ci Please test |
|
@swift-ci test |
| @available(SwiftStdlib 5.3, *) | ||
| public init?(_ text: Substring) { | ||
| // TODO: Someday, this whole function should simplify down to just: | ||
| // ${Self}(text.utf8.span) |
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.
Can we spell it that way for the platforms that don't have availability issues?
There are examples of tests of bridged substrings in test/stdlib/Span/BridgedStringUTF8ViewSpanTests.swift |
The new FP parsing code inadvertently used the entire backing string, even when the substring referred to just a portion.
This addresses a failure in the extended
UnicodeScalarProperties.swifttest, which parses an input file by reading a line into a String, then extracting Substrings. (rdar://166258748)