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 3
3
use crate :: slice;
4
4
use crate :: str:: from_utf8_unchecked_mut;
5
5
use crate :: unicode:: printable:: is_printable;
6
- use crate :: unicode:: { self , conversions, ASCII_CASE_MASK } ;
6
+ use crate :: unicode:: { self , conversions} ;
7
7
8
8
use super :: * ;
9
9
@@ -1090,7 +1090,11 @@ impl char {
1090
1090
#[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
1091
1091
#[ inline]
1092
1092
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
+ }
1094
1098
}
1095
1099
1096
1100
/// Makes a copy of the value in its ASCII lower case equivalent.
@@ -1118,7 +1122,11 @@ impl char {
1118
1122
#[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
1119
1123
#[ inline]
1120
1124
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
+ }
1122
1130
}
1123
1131
1124
1132
/// Checks that two values are an ASCII case-insensitive match.
Original file line number Diff line number Diff line change 5
5
use crate :: intrinsics;
6
6
use crate :: mem;
7
7
use 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 ;
9
11
10
12
// Used because the `?` operator is not allowed in a const context.
11
13
macro_rules! try_opt {
@@ -222,6 +224,12 @@ impl u8 {
222
224
* self | ( self . is_ascii_uppercase ( ) as u8 * ASCII_CASE_MASK )
223
225
}
224
226
227
+ /// Assumes self is ascii
228
+ #[ inline]
229
+ pub ( crate ) fn ascii_change_case_unchecked ( & self ) -> u8 {
230
+ * self ^ ASCII_CASE_MASK
231
+ }
232
+
225
233
/// Checks that two values are an ASCII case-insensitive match.
226
234
///
227
235
/// 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;
17
17
#[ stable( feature = "unicode_version" , since = "1.45.0" ) ]
18
18
pub const UNICODE_VERSION : ( u8 , u8 , u8 ) = unicode_data:: UNICODE_VERSION ;
19
19
20
- /// If 6th bit set ascii is upper case.
21
- pub ( crate ) const ASCII_CASE_MASK : u8 = 0b0010_0000 ;
22
-
23
20
// For use in liballoc, not re-exported in libstd.
24
21
pub use unicode_data:: {
25
22
case_ignorable:: lookup as Case_Ignorable , cased:: lookup as Cased , conversions,
You can’t perform that action at this time.
0 commit comments