Skip to content

Commit 77aae74

Browse files
committed
Fix panics in Ascii's .is_xxx() methods by specifying wrapping sub.
1 parent c575fdf commit 77aae74

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/ascii.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,25 @@ impl Ascii {
9696
/// Checks if the character is printable (except space)
9797
#[inline]
9898
pub fn is_graph(&self) -> bool {
99-
(self.chr - 0x21) < 0x5E
99+
self.chr.wrapping_sub(0x21) < 0x5E
100100
}
101101

102102
/// Checks if the character is printable (including space)
103103
#[inline]
104104
pub fn is_print(&self) -> bool {
105-
(self.chr - 0x20) < 0x5F
105+
self.chr.wrapping_sub(0x20) < 0x5F
106106
}
107107

108108
/// Checks if the character is alphabetic and lowercase
109109
#[inline]
110110
pub fn is_lowercase(&self) -> bool {
111-
(self.chr - b'a') < 26
111+
self.chr.wrapping_sub(b'a') < 26
112112
}
113113

114114
/// Checks if the character is alphabetic and uppercase
115115
#[inline]
116116
pub fn is_uppercase(&self) -> bool {
117-
(self.chr - b'A') < 26
117+
self.chr.wrapping_sub(b'A') < 26
118118
}
119119

120120
/// Checks if the character is punctuation
@@ -126,7 +126,7 @@ impl Ascii {
126126
/// Checks if the character is a valid hex digit
127127
#[inline]
128128
pub fn is_hex(&self) -> bool {
129-
self.is_digit() || ((self.chr | 32u8) - b'a') < 6
129+
self.is_digit() || (self.chr | 32u8).wrapping_sub(b'a') < 6
130130
}
131131
}
132132

0 commit comments

Comments
 (0)