diff options
| author | bors <bors@rust-lang.org> | 2013-11-27 11:52:09 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-27 11:52:09 -0800 |
| commit | e147a090a5c7125428c16b142922002f7a645ea1 (patch) | |
| tree | 275b1a2931d620828c3e20ffbdf3a8bc03dbb4b9 /src/libstd | |
| parent | e4136bd552bc7bf2b83ceb5d114f9a254bfa2b01 (diff) | |
| parent | 64883242ebece291170d86483cb1b3656ddc3d23 (diff) | |
| download | rust-e147a090a5c7125428c16b142922002f7a645ea1.tar.gz rust-e147a090a5c7125428c16b142922002f7a645ea1.zip | |
auto merge of #10685 : ebiggers/rust/ascii_fixes, r=alexcrichton
is_digit() incorrectly returned false for '0'. is_control() incorrectly returned true for ' ' (space).
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 18b6a1ef52a..c43b4e9b6ea 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -67,7 +67,7 @@ impl Ascii { /// Check if the character is a number (0-9) #[inline] pub fn is_digit(&self) -> bool { - self.chr >= 0x31 && self.chr <= 0x39 + self.chr >= 0x30 && self.chr <= 0x39 } /// Check if the character is a letter or number @@ -85,7 +85,7 @@ impl Ascii { /// Check if the character is a control character #[inline] pub fn is_control(&self) -> bool { - self.chr <= 0x20 || self.chr == 0x7F + self.chr < 0x20 || self.chr == 0x7F } /// Checks if the character is printable (except space) @@ -498,6 +498,15 @@ mod tests { assert_eq!('`'.to_ascii().to_upper().to_char(), '`'); assert_eq!('{'.to_ascii().to_upper().to_char(), '{'); + assert!('0'.to_ascii().is_digit()); + assert!('9'.to_ascii().is_digit()); + assert!(!'/'.to_ascii().is_digit()); + assert!(!':'.to_ascii().is_digit()); + + assert!((0x1fu8).to_ascii().is_control()); + assert!(!' '.to_ascii().is_control()); + assert!((0x7fu8).to_ascii().is_control()); + assert!("banana".chars().all(|c| c.is_ascii())); assert!(!"ประเทศไทย中华Việt Nam".chars().all(|c| c.is_ascii())); } |
