-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Supported Scanner API for Swift #1914
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
@swift-ci please test |
@swift-ci Please test source compatibility |
… worth a try. |
@shahmishal is it possible to set up 'please test source compatibility' for s-c-f? |
} | ||
|
||
public func scanInt(representation: NumberRepresentation = .decimal) -> Int? { | ||
#if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le) |
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.
Would it be better to write this as if Int.bitWidth == Int64.bitWidth
to avoid having to maintain a list of archs?
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.
We use this in Data
as well just to save the runtime check.
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.
Wouldnt it be a constant expression and optimised away by the compiler?
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.
There were issues with that IIRC, and it may or may not be.
I bet the issue with the test is that one of the emoji isn't recognized as an emoji by ICU 61. |
var value = Int32.max | ||
switch representation { | ||
case .decimal: guard self.scanInt32(&value) else { return nil } | ||
default: |
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.
should this be case .hexadecimal
instead of .default
?
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.
Good catch, yep.
Are |
@millenomi because of https://bugs.swift.org/browse/SR-9699 the CI tests arent even building ICU so might be worth getting it fixed now ;) |
|
||
// Overflow: | ||
withScanner(for: "\(Int64.max)0") { | ||
expectEqual($0.scanInt64(), Int64.max, "Overflow") |
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.
So is there anyway to detect if a number being scanned is >Int64.max
? Or have a flag to say dont clip to Int64.max
?
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.
It can't not clip to a Int64 value, since it returns a Int64. This is consistent with the behavior of the older methods.
@spevans it is indeed https://bugs.swift.org/browse/SR-9699 — I pinged @shahmishal about it. |
|
||
// On overflow, the below methods will return success and clamp | ||
@discardableResult | ||
open func scanInt32(_ result: UnsafeMutablePointer<Int32>) -> Bool { |
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.
Am I misreading the Scanner documentation or should all of these scanXXX(_ result: UnsafeMutablePointer<XXX>) -> Bool
methods actually take an optional pointer?
https://developer.apple.com/documentation/foundation/scanner/1410914-scanint32
Looks like they may have always been wrong?
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.
Yeah, good catch. I'll follow up to correct the signatures.
Yes, can you file a Jira bug? |
@swift-ci test |
Add API on Scanner that's more idiomatic for use in Swift. This promotes some of the existing experimental API and deprecates the rest. The new API is intended to operate on graphemes, not single UTF-16 code units. This API is not experimental and will be supported going forward.