Skip to content

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions stdlib/public/core/IntegerParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,31 @@ extension FixedWidthInteger {
public init?(_ description: String) {
self.init(description, radix: 10)
}

/// Creates a new integer value from the given Substring.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Creates a new integer value from the given Substring.
/// Creates a new integer value from the given `Substring`.

///
/// Substring can be parsed at a high speed just by substituting strings.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Substring can be parsed at a high speed just by substituting strings.

This is not relevant to the user-facing documentation.

///
/// The Substring passed as `description` may begin with a plus or minus sign
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The Substring passed as `description` may begin with a plus or minus sign
/// The `Substring` passed as `description` may begin with a plus or minus sign

/// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs availability annotations for the standard library, and probably @_alwaysEmitIntoClient for ABI reasons. I forget exactly, but I think that implies @inlinable.

@_semantics("optimize.sil.specialize.generic.partial.never")
@inline(__always)
public init?(_ description: Substring) {
self.init(String(description), radix: 10)
}
}