Skip to content

Commit 591c1f2

Browse files
committed
introduce {char, u8}::is_ascii_octdigit
1 parent cd4d9d9 commit 591c1f2

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

library/core/src/char/methods.rs

+32
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,38 @@ impl char {
14441444
matches!(*self, '0'..='9')
14451445
}
14461446

1447+
/// Checks if the value is an ASCII octal digit:
1448+
/// U+0030 '0' ..= U+0037 '7'.
1449+
///
1450+
/// # Examples
1451+
///
1452+
/// ```
1453+
/// #![feature(is_ascii_octdigit)]
1454+
///
1455+
/// let uppercase_a = 'A';
1456+
/// let a = 'a';
1457+
/// let zero = '0';
1458+
/// let seven = '7';
1459+
/// let nine = '9';
1460+
/// let percent = '%';
1461+
/// let lf = '\n';
1462+
///
1463+
/// assert!(!uppercase_a.is_ascii_octdigit());
1464+
/// assert!(!a.is_ascii_octdigit());
1465+
/// assert!(zero.is_ascii_octdigit());
1466+
/// assert!(seven.is_ascii_octdigit());
1467+
/// assert!(!nine.is_ascii_octdigit());
1468+
/// assert!(!percent.is_ascii_octdigit());
1469+
/// assert!(!lf.is_ascii_octdigit());
1470+
/// ```
1471+
#[must_use]
1472+
#[unstable(feature = "is_ascii_octdigit", issue = "101288")]
1473+
#[rustc_const_unstable(feature = "is_ascii_octdigit", issue = "101288")]
1474+
#[inline]
1475+
pub const fn is_ascii_octdigit(&self) -> bool {
1476+
matches!(*self, '0'..='7')
1477+
}
1478+
14471479
/// Checks if the value is an ASCII hexadecimal digit:
14481480
///
14491481
/// - U+0030 '0' ..= U+0039 '9', or

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
#![feature(const_slice_index)]
165165
#![feature(const_is_char_boundary)]
166166
#![feature(const_cstr_methods)]
167+
#![feature(is_ascii_octdigit)]
167168
//
168169
// Language features:
169170
#![feature(abi_unadjusted)]

library/core/src/num/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,38 @@ impl u8 {
622622
matches!(*self, b'0'..=b'9')
623623
}
624624

625+
/// Checks if the value is an ASCII octal digit:
626+
/// U+0030 '0' ..= U+0037 '7'.
627+
///
628+
/// # Examples
629+
///
630+
/// ```
631+
/// #![feature(is_ascii_octdigit)]
632+
///
633+
/// let uppercase_a = b'A';
634+
/// let a = b'a';
635+
/// let zero = b'0';
636+
/// let seven = b'7';
637+
/// let nine = b'9';
638+
/// let percent = b'%';
639+
/// let lf = b'\n';
640+
///
641+
/// assert!(!uppercase_a.is_ascii_octdigit());
642+
/// assert!(!a.is_ascii_octdigit());
643+
/// assert!(zero.is_ascii_octdigit());
644+
/// assert!(seven.is_ascii_octdigit());
645+
/// assert!(!nine.is_ascii_octdigit());
646+
/// assert!(!percent.is_ascii_octdigit());
647+
/// assert!(!lf.is_ascii_octdigit());
648+
/// ```
649+
#[must_use]
650+
#[unstable(feature = "is_ascii_octdigit", issue = "101288")]
651+
#[rustc_const_unstable(feature = "is_ascii_octdigit", issue = "101288")]
652+
#[inline]
653+
pub const fn is_ascii_octdigit(&self) -> bool {
654+
matches!(*self, b'0'..=b'7')
655+
}
656+
625657
/// Checks if the value is an ASCII hexadecimal digit:
626658
///
627659
/// - U+0030 '0' ..= U+0039 '9', or

library/core/tests/ascii.rs

+18
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,23 @@ fn test_is_ascii_digit() {
251251
);
252252
}
253253

254+
#[test]
255+
fn test_is_ascii_octdigit() {
256+
assert_all!(is_ascii_octdigit, "", "01234567");
257+
assert_none!(
258+
is_ascii_octdigit,
259+
"abcdefghijklmnopqrstuvwxyz",
260+
"ABCDEFGHIJKLMNOQPRSTUVWXYZ",
261+
"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
262+
" \t\n\x0c\r",
263+
"\x00\x01\x02\x03\x04\x05\x06\x07",
264+
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
265+
"\x10\x11\x12\x13\x14\x15\x16\x17",
266+
"\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
267+
"\x7f",
268+
);
269+
}
270+
254271
#[test]
255272
fn test_is_ascii_hexdigit() {
256273
assert_all!(is_ascii_hexdigit, "", "0123456789", "abcdefABCDEF",);
@@ -454,6 +471,7 @@ fn ascii_ctype_const() {
454471
is_ascii_lowercase => [true, false, false, false, false];
455472
is_ascii_alphanumeric => [true, true, true, false, false];
456473
is_ascii_digit => [false, false, true, false, false];
474+
is_ascii_octdigit => [false, false, false, false, false];
457475
is_ascii_hexdigit => [true, true, true, false, false];
458476
is_ascii_punctuation => [false, false, false, true, false];
459477
is_ascii_graphic => [true, true, true, true, false];

library/core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#![feature(slice_flatten)]
102102
#![feature(provide_any)]
103103
#![feature(utf8_chunks)]
104+
#![feature(is_ascii_octdigit)]
104105
#![deny(unsafe_op_in_unsafe_fn)]
105106

106107
extern crate test;

0 commit comments

Comments
 (0)