-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Create integerparsing init for substring #36413
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -197,4 +197,31 @@ extension FixedWidthInteger { | |||||
public init?(_ description: String) { | ||||||
self.init(description, radix: 10) | ||||||
} | ||||||
|
||||||
/// Creates a new integer value from the given Substring. | ||||||
/// | ||||||
/// Substring can be parsed at a high speed just by substituting strings. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is not relevant to the user-facing documentation. |
||||||
/// | ||||||
/// The Substring passed as `description` may begin with a plus or minus sign | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// character (`+` or `-`), followed by one or more numeric digits (`0-9`). | ||||||
/// | ||||||
/// let x = Int("123") | ||||||
/// // x == 123 | ||||||
/// | ||||||
/// If `description` is in an invalid format, or if the value it denotes in | ||||||
/// base 10 is not representable, the result is `nil`. For example, the | ||||||
/// following conversions result in `nil`: | ||||||
/// | ||||||
/// Int(" 100") // Includes whitespace | ||||||
/// Int("21-50") // Invalid format | ||||||
/// Int("ff6600") // Characters out of bounds | ||||||
/// Int("10000000000000000000000000") // Out of range | ||||||
/// | ||||||
/// - Parameter description: The ASCII representation of a number. | ||||||
@inlinable | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs availability annotations for the standard library, and probably |
||||||
@_semantics("optimize.sil.specialize.generic.partial.never") | ||||||
@inline(__always) | ||||||
public init?(_ description: Substring) { | ||||||
self.init(String(description), radix: 10) | ||||||
} | ||||||
} |
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.