Skip to content
Open
Show file tree
Hide file tree
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: 17 additions & 10 deletions src/ascii_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,15 @@ impl AsciiChar {
///
/// # Panics
///
/// Radixes greater than 36 are not supported and will result in a panic.
/// Panics if given a radix smaller than 2 or larger than 36.
#[must_use]
pub fn is_digit(self, radix: u32) -> bool {
match (self as u8, radix) {
(b'0'..=b'9', 0..=36) => u32::from(self as u8 - b'0') < radix,
(b'0'..=b'9', 2..=36) => u32::from(self as u8 - b'0') < radix,
(b'a'..=b'z', 11..=36) => u32::from(self as u8 - b'a') < radix - 10,
(b'A'..=b'Z', 11..=36) => u32::from(self as u8 - b'A') < radix - 10,
(_, 0..=36) => false,
(_, _) => panic!("radixes greater than 36 are not supported"),
(_, 2..=36) => false,
(_, _) => panic!("radix must be in the range 2 to 36 inclusive"),
}
}

Expand Down Expand Up @@ -704,7 +704,7 @@ impl AsciiChar {
// the unprintable characters from 0x0 to 0x1f, ordered correctly.
// As `b` is guaranteed to be within 0x0 to 0x1f, the conversion represents a
// valid character.
b @ 0x0..=0x1f => unsafe { mem::transmute('␀' as u32 + b as u32) },
b @ 0x0..=0x1f => unsafe { char::from_u32_unchecked('␀' as u32 + b as u32) },

// 0x7f (delete) has it's own character at codepoint 0x2420, not 0x247f, so it is special
// cased to return it's character
Expand Down Expand Up @@ -794,8 +794,8 @@ macro_rules! impl_into_partial_eq_ord {
($wider:ty, $to_wider:expr) => {
impl From<AsciiChar> for $wider {
#[inline]
fn from(a: AsciiChar) -> $wider {
$to_wider(a)
fn from(chr: AsciiChar) -> $wider {
$to_wider(chr)
}
}
impl PartialEq<$wider> for AsciiChar {
Expand Down Expand Up @@ -1050,15 +1050,22 @@ mod tests {

#[test]
fn is_digit_strange_radixes() {
assert_eq!(AsciiChar::_0.is_digit(0), '0'.is_digit(0));
assert_eq!(AsciiChar::_0.is_digit(1), '0'.is_digit(1));
assert_eq!(AsciiChar::_0.is_digit(2), '0'.is_digit(2));
assert_eq!(AsciiChar::_1.is_digit(2), '1'.is_digit(2));
assert_eq!(AsciiChar::_2.is_digit(2), '2'.is_digit(2));
assert_eq!(AsciiChar::_5.is_digit(5), '5'.is_digit(5));
assert_eq!(AsciiChar::z.is_digit(35), 'z'.is_digit(35));
}

#[test]
#[should_panic]
fn is_digit_bad_radix() {
fn is_digit_bad_radix_small() {
let _ = AsciiChar::_0.is_digit(1);
}

#[test]
#[should_panic]
fn is_digit_bad_radix_big() {
let _ = AsciiChar::_7.is_digit(37);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ascii_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ impl AsciiStr {
/// Returns an iterator over the characters of the `AsciiStr`.
#[inline]
#[must_use]
pub fn chars(&self) -> Chars {
pub fn chars(&self) -> Chars<'_> {
Chars(self.slice.iter())
}

/// Returns an iterator over the characters of the `AsciiStr` which allows you to modify the
/// value of each `AsciiChar`.
#[inline]
#[must_use]
pub fn chars_mut(&mut self) -> CharsMut {
pub fn chars_mut(&mut self) -> CharsMut<'_> {
CharsMut(self.slice.iter_mut())
}

Expand Down