@@ -96,10 +96,10 @@ pub struct Codepoint(u32);
96
96
impl Codepoint {
97
97
// Equivalent to BYTE8_TO_CHAR
98
98
/// Create a codepoint from a raw byte. If non-ascii, byte8 encode it.
99
- pub fn from_raw ( byte : u8 ) -> Codepoint {
100
- match Codepoint :: from ( byte) {
99
+ pub fn from_raw ( byte : u8 ) -> Self {
100
+ match Self :: from ( byte) {
101
101
cp if cp. is_ascii ( ) => cp,
102
- cp => Codepoint :: from ( cp. 0 + BYTE8_OFFSET ) ,
102
+ cp => Self :: from ( cp. 0 + BYTE8_OFFSET ) ,
103
103
}
104
104
}
105
105
@@ -145,9 +145,10 @@ impl Codepoint {
145
145
/// Note that this does not check if the codepoint is within the
146
146
/// appropriate range.
147
147
pub fn to_byte8_unchecked ( self ) -> u8 {
148
- match self . is_byte8 ( ) {
149
- true => ( self . 0 - BYTE8_OFFSET ) as u8 ,
150
- false => ( self . 0 & 0xFF ) as u8 ,
148
+ if self . is_byte8 ( ) {
149
+ ( self . 0 - BYTE8_OFFSET ) as u8
150
+ } else {
151
+ ( self . 0 & 0xFF ) as u8
151
152
}
152
153
}
153
154
@@ -165,16 +166,17 @@ impl Codepoint {
165
166
}
166
167
167
168
// Equivalent to UNIBYTE_TO_CHAR
168
- pub fn unibyte_to_char ( self ) -> Codepoint {
169
- match self . is_ascii ( ) {
170
- true => self ,
171
- false => Codepoint :: from_raw ( self . 0 as u8 ) ,
169
+ pub fn unibyte_to_char ( self ) -> Self {
170
+ if self . is_ascii ( ) {
171
+ self
172
+ } else {
173
+ Self :: from_raw ( self . 0 as u8 )
172
174
}
173
175
}
174
176
175
177
// Equivalent to MAKE_CHAR_MULTIBYTE
176
178
/// Transform an 8-bit codepoint to its byte8 encoded form.
177
- pub fn to_multibyte ( self ) -> Codepoint {
179
+ pub fn to_multibyte ( self ) -> Self {
178
180
debug_assert ! ( self . is_single_byte( ) ) ;
179
181
self . unibyte_to_char ( )
180
182
}
@@ -211,7 +213,7 @@ impl Codepoint {
211
213
to[ 0 ] = 0xF8 ;
212
214
5
213
215
} else if cp <= MAX_CHAR {
214
- let b = Codepoint :: from ( cp) . to_byte8_unchecked ( ) ;
216
+ let b = Self :: from ( cp) . to_byte8_unchecked ( ) ;
215
217
to[ 1 ] = 0x80 | ( b & 0x3F ) ;
216
218
to[ 0 ] = 0xC0 | ( ( b >> 6 ) & 1 ) ;
217
219
2
@@ -222,11 +224,11 @@ impl Codepoint {
222
224
223
225
/// If character code C has modifier masks, reflect them to the character
224
226
/// code if possible. Return the resulting code.
225
- pub fn resolve_modifier_mask ( self ) -> Codepoint {
227
+ pub fn resolve_modifier_mask ( self ) -> Self {
226
228
let mut cp = self . 0 ;
227
229
// A non-ASCII character can't reflect modifier bits to the code.
228
- if !Codepoint :: from ( cp & !char_bits:: CHAR_MODIFIER_MASK ) . is_ascii ( ) {
229
- return Codepoint :: from ( cp) ;
230
+ if !Self :: from ( cp & !char_bits:: CHAR_MODIFIER_MASK ) . is_ascii ( ) {
231
+ return Self :: from ( cp) ;
230
232
}
231
233
let ascii = ( cp & 0x7F ) as u8 ;
232
234
// For Meta, Shift, and Control modifiers, we need special care.
@@ -253,7 +255,7 @@ impl Codepoint {
253
255
cp &= 0x1F | ( !0x7F & !char_bits:: CHAR_CTL ) ;
254
256
}
255
257
}
256
- Codepoint :: from ( cp)
258
+ Self :: from ( cp)
257
259
}
258
260
}
259
261
@@ -322,7 +324,7 @@ impl From<Codepoint> for LispObject {
322
324
impl From < LispObject > for Codepoint {
323
325
fn from ( o : LispObject ) -> Self {
324
326
match o. as_fixnum ( ) {
325
- Some ( i) if 0 <= i && i <= EmacsInt :: from ( MAX_CHAR ) => Codepoint :: from ( i as u32 ) ,
327
+ Some ( i) if 0 <= i && i <= EmacsInt :: from ( MAX_CHAR ) => Self :: from ( i as u32 ) ,
326
328
_ => wrong_type ! ( Qcharacterp , o) ,
327
329
}
328
330
}
@@ -1080,10 +1082,10 @@ pub unsafe extern "C" fn str_to_unibyte(
1080
1082
srcslice = & srcslice[ cplen..] ;
1081
1083
dstslice[ i as usize ] = if cp. val ( ) > MAX_5_BYTE_CHAR {
1082
1084
cp. to_byte8_unchecked ( )
1083
- } else if !cp. is_ascii ( ) {
1084
- return i;
1085
- } else {
1085
+ } else if cp. is_ascii ( ) {
1086
1086
cp. 0 as c_uchar
1087
+ } else {
1088
+ return i;
1087
1089
} ;
1088
1090
}
1089
1091
chars
0 commit comments