From c416b7104a8e7ebab335ce4a8be9e389035d21a1 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Wed, 24 Mar 2021 16:54:31 -0500 Subject: [PATCH] Rename to to_ascii_digit_radix, add issue number --- library/core/src/num/mod.rs | 19 +++++++++++-------- library/core/tests/ascii.rs | 24 ++++++++++++------------ library/core/tests/lib.rs | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 148b94a344bc1..93497341f2f64 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -714,27 +714,30 @@ impl u8 { /// Basic usage: /// /// ``` - /// assert_eq!(b'1'.to_digit(10), Some(1)); - /// assert_eq!(b'f'.to_digit(16), Some(15)); + /// #![feature(to_ascii_digit)] + /// assert_eq!(b'1'.to_ascii_digit_radix(10), Some(1)); + /// assert_eq!(b'f'.to_ascii_digit_radix(16), Some(15)); /// ``` /// /// Passing a non-digit results in failure: /// /// ``` - /// assert_eq!(b'f'.to_digit(10), None); - /// assert_eq!(b'z'.to_digit(16), None); + /// #![feature(to_ascii_digit)] + /// assert_eq!(b'f'.to_ascii_digit_radix(10), None); + /// assert_eq!(b'z'.to_ascii_digit_radix(16), None); /// ``` /// /// Passing a large radix, causing a panic: /// /// ```should_panic + /// #![feature(to_ascii_digit)] /// // this panics - /// b'1'.to_digit(37); + /// b'1'.to_ascii_digit_radix(37); /// ``` - #[unstable(feature = "ascii_to_digit", issue = "none")] + #[unstable(feature = "to_ascii_digit", issue = "83447")] #[inline] - pub fn to_digit(&self, radix: u32) -> Option { - assert!(radix <= 36, "to_digit: radix is too high (maximum 36)"); + pub fn to_ascii_digit_radix(&self, radix: u32) -> Option { + assert!(radix <= 36, "to_ascii_digit_radix: radix is too high (maximum 36)"); // the code is split up here to improve execution speed for cases where // the `radix` is constant and 10 or smaller let val = if intrinsics::likely(radix <= 10) { diff --git a/library/core/tests/ascii.rs b/library/core/tests/ascii.rs index 85ac8d28476b3..577eda158f053 100644 --- a/library/core/tests/ascii.rs +++ b/library/core/tests/ascii.rs @@ -347,18 +347,18 @@ fn test_is_ascii_control() { #[cfg(not(bootstrap))] #[test] fn test_to_digit() { - assert_eq!(b'0'.to_digit(10), Some(0)); - assert_eq!(b'1'.to_digit(2), Some(1)); - assert_eq!(b'2'.to_digit(3), Some(2)); - assert_eq!(b'9'.to_digit(10), Some(9)); - assert_eq!(b'a'.to_digit(16), Some(10)); - assert_eq!(b'A'.to_digit(16), Some(10)); - assert_eq!(b'b'.to_digit(16), Some(11)); - assert_eq!(b'B'.to_digit(16), Some(11)); - assert_eq!(b'z'.to_digit(36), Some(35)); - assert_eq!(b'Z'.to_digit(36), Some(35)); - assert_eq!(b' '.to_digit(10), None); - assert_eq!(b'$'.to_digit(36), None); + assert_eq!(b'0'.to_ascii_digit_radix(10), Some(0)); + assert_eq!(b'1'.to_ascii_digit_radix(2), Some(1)); + assert_eq!(b'2'.to_ascii_digit_radix(3), Some(2)); + assert_eq!(b'9'.to_ascii_digit_radix(10), Some(9)); + assert_eq!(b'a'.to_ascii_digit_radix(16), Some(10)); + assert_eq!(b'A'.to_ascii_digit_radix(16), Some(10)); + assert_eq!(b'b'.to_ascii_digit_radix(16), Some(11)); + assert_eq!(b'B'.to_ascii_digit_radix(16), Some(11)); + assert_eq!(b'z'.to_ascii_digit_radix(36), Some(35)); + assert_eq!(b'Z'.to_ascii_digit_radix(36), Some(35)); + assert_eq!(b' '.to_ascii_digit_radix(10), None); + assert_eq!(b'$'.to_ascii_digit_radix(36), None); } // `is_ascii` does a good amount of pointer manipulation and has diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index fc3f38009752c..48de0c7c69021 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -4,7 +4,6 @@ #![feature(array_methods)] #![feature(array_map)] #![feature(array_windows)] -#![cfg_attr(not(bootstrap), feature(ascii_to_digit))] #![feature(bool_to_option)] #![feature(bound_cloned)] #![feature(box_syntax)] @@ -45,6 +44,7 @@ #![feature(step_trait_ext)] #![feature(str_internals)] #![feature(test)] +#![cfg_attr(not(bootstrap), feature(to_ascii_digit))] #![feature(trusted_len)] #![feature(try_trait)] #![feature(slice_internals)]