diff options
| author | Giles Cope <gilescope@gmail.com> | 2021-02-06 20:35:21 +0000 |
|---|---|---|
| committer | Giles Cope <gilescope@gmail.com> | 2021-02-06 20:35:21 +0000 |
| commit | f30c51abe8ce62756f86abbbd6623a9131d3954c (patch) | |
| tree | 9dad7427e4d972461840277cab91bbfef81e6d26 | |
| parent | f165f49d228d2582d2dbfd588c2729cfc9585eb0 (diff) | |
| download | rust-f30c51abe8ce62756f86abbbd6623a9131d3954c.tar.gz rust-f30c51abe8ce62756f86abbbd6623a9131d3954c.zip | |
Pulling out constant.
| -rw-r--r-- | library/core/src/char/methods.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 4c28d9cd673..4032e777077 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -7,6 +7,9 @@ use crate::unicode::{self, conversions}; use super::*; +/// If 6th bit set ascii is upper case. +const ASCII_CASE_MASK: u8 = 0b10_0000u8; + #[lang = "char"] impl char { /// The highest valid code point a `char` can have. @@ -1090,8 +1093,7 @@ impl char { #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[inline] pub fn to_ascii_uppercase(&self) -> char { - // 6th bit dictates ascii case. - if self.is_ascii_lowercase() { ((*self as u8) & !0b10_0000u8) as char } else { *self } + if self.is_ascii_lowercase() { ((*self as u8) & !ASCII_CASE_MASK) as char } else { *self } } /// Makes a copy of the value in its ASCII lower case equivalent. @@ -1119,8 +1121,7 @@ impl char { #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[inline] pub fn to_ascii_lowercase(&self) -> char { - // 6th bit dictates ascii case. - if self.is_ascii_uppercase() { ((*self as u8) | 0b10_0000u8) as char } else { *self } + if self.is_ascii_uppercase() { ((*self as u8) | ASCII_CASE_MASK) as char } else { *self } } /// Checks that two values are an ASCII case-insensitive match. |
