File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change 33use crate :: slice;
44use crate :: str:: from_utf8_unchecked_mut;
55use crate :: unicode:: printable:: is_printable;
6- use crate :: unicode:: { self , conversions, ASCII_CASE_MASK } ;
6+ use crate :: unicode:: { self , conversions} ;
77
88use super :: * ;
99
@@ -1090,7 +1090,11 @@ impl char {
10901090 #[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
10911091 #[ inline]
10921092 pub fn to_ascii_uppercase ( & self ) -> char {
1093- if self . is_ascii_lowercase ( ) { ( ( * self as u8 ) & !ASCII_CASE_MASK ) as char } else { * self }
1093+ if self . is_ascii_lowercase ( ) {
1094+ ( * self as u8 ) . ascii_change_case_unchecked ( ) as char
1095+ } else {
1096+ * self
1097+ }
10941098 }
10951099
10961100 /// Makes a copy of the value in its ASCII lower case equivalent.
@@ -1118,7 +1122,11 @@ impl char {
11181122 #[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
11191123 #[ inline]
11201124 pub fn to_ascii_lowercase ( & self ) -> char {
1121- if self . is_ascii_uppercase ( ) { ( ( * self as u8 ) | ASCII_CASE_MASK ) as char } else { * self }
1125+ if self . is_ascii_uppercase ( ) {
1126+ ( * self as u8 ) . ascii_change_case_unchecked ( ) as char
1127+ } else {
1128+ * self
1129+ }
11221130 }
11231131
11241132 /// Checks that two values are an ASCII case-insensitive match.
Original file line number Diff line number Diff line change 55use crate :: intrinsics;
66use crate :: mem;
77use crate :: str:: FromStr ;
8- use crate :: unicode:: ASCII_CASE_MASK ;
8+
9+ /// If 6th bit set ascii is upper case.
10+ const ASCII_CASE_MASK : u8 = 0b0010_0000 ;
911
1012// Used because the `?` operator is not allowed in a const context.
1113macro_rules! try_opt {
@@ -222,6 +224,12 @@ impl u8 {
222224 * self | ( self . is_ascii_uppercase ( ) as u8 * ASCII_CASE_MASK )
223225 }
224226
227+ /// Assumes self is ascii
228+ #[ inline]
229+ pub ( crate ) fn ascii_change_case_unchecked ( & self ) -> u8 {
230+ * self ^ ASCII_CASE_MASK
231+ }
232+
225233 /// Checks that two values are an ASCII case-insensitive match.
226234 ///
227235 /// This is equivalent to `to_ascii_lowercase(a) == to_ascii_lowercase(b)`.
Original file line number Diff line number Diff line change @@ -17,9 +17,6 @@ mod unicode_data;
1717#[ stable( feature = "unicode_version" , since = "1.45.0" ) ]
1818pub const UNICODE_VERSION : ( u8 , u8 , u8 ) = unicode_data:: UNICODE_VERSION ;
1919
20- /// If 6th bit set ascii is upper case.
21- pub ( crate ) const ASCII_CASE_MASK : u8 = 0b0010_0000 ;
22-
2320// For use in liballoc, not re-exported in libstd.
2421pub use unicode_data:: {
2522 case_ignorable:: lookup as Case_Ignorable , cased:: lookup as Cased , conversions,
You can’t perform that action at this time.
0 commit comments