diff --git a/src/euc_jp.rs b/src/euc_jp.rs index bf95a1f..09fd4ff 100644 --- a/src/euc_jp.rs +++ b/src/euc_jp.rs @@ -24,10 +24,7 @@ enum EucJpPending { impl EucJpPending { fn is_none(&self) -> bool { - match *self { - EucJpPending::None => true, - _ => false, - } + matches!(*self, EucJpPending::None) } fn count(&self) -> usize { diff --git a/src/gb18030.rs b/src/gb18030.rs index 5cfd97e..39ac42c 100644 --- a/src/gb18030.rs +++ b/src/gb18030.rs @@ -25,10 +25,7 @@ enum Gb18030Pending { impl Gb18030Pending { fn is_none(&self) -> bool { - match *self { - Gb18030Pending::None => true, - _ => false, - } + matches!(*self, Gb18030Pending::None) } fn count(&self) -> usize { @@ -270,7 +267,7 @@ impl Gb18030Decoder { } else { handle.write_bmp_excl_ascii(gb18030_range_decode(pointer as u16)) } - } else if pointer >= 189_000 && pointer <= 1_237_575 { + } else if (189_000..=1_237_575).contains(&pointer) { // Astral handle.write_astral((pointer - (189_000usize - 0x1_0000usize)) as u32) } else { diff --git a/src/iso_2022_jp.rs b/src/iso_2022_jp.rs index 39bb38c..5589a6f 100644 --- a/src/iso_2022_jp.rs +++ b/src/iso_2022_jp.rs @@ -190,7 +190,7 @@ impl Iso2022JpDecoder { continue; } self.output_flag = false; - if b >= 0x21u8 && b <= 0x5Fu8 { + if (0x21u8..=0x5Fu8).contains(&b) { destination_handle.write_upper_bmp(u16::from(b) - 0x21u16 + 0xFF61u16); continue; } @@ -206,7 +206,7 @@ impl Iso2022JpDecoder { continue; } self.output_flag = false; - if b >= 0x21u8 && b <= 0x7Eu8 { + if (0x21u8..=0x7Eu8).contains(&b) { self.lead = b; self.decoder_state = Iso2022JpDecoderState::TrailByte; continue; @@ -376,19 +376,12 @@ fn is_kanji_mapped(bmp: u16) -> bool { #[allow(clippy::redundant_pattern_matching, clippy::if_same_then_else)] #[inline(always)] fn is_kanji_mapped(bmp: u16) -> bool { - if 0x4EDD == bmp { - true - } else if let Some(_) = jis0208_level1_kanji_shift_jis_encode(bmp) { + 0x4EDD == bmp + || matches!(jis0208_level1_kanji_shift_jis_encode(bmp), Some(_)) // Use the shift_jis variant, because we don't care about the // byte values here. - true - } else if let Some(_) = jis0208_level2_and_additional_kanji_encode(bmp) { - true - } else if let Some(_) = position(&IBM_KANJI[..], bmp) { - true - } else { - false - } + || matches!(jis0208_level2_and_additional_kanji_encode(bmp), Some(_)) + || matches!(position(&IBM_KANJI[..], bmp), Some(_)) } #[allow(clippy::redundant_pattern_matching, clippy::if_same_then_else)] @@ -407,24 +400,16 @@ fn is_mapped_for_two_byte_encode(bmp: u16) -> bool { true } else { let bmp_minus_space = bmp.wrapping_sub(0x3000); - if bmp_minus_space < 3 { - // fast-track common punctuation - true - } else if in_inclusive_range16(bmp, 0xFF61, 0xFF9F) { - true - } else if bmp == 0x2212 { - true - } else if let Some(_) = jis0208_range_encode(bmp) { - true - } else if in_inclusive_range16(bmp, 0xFA0E, 0xFA2D) || bmp == 0xF929 || bmp == 0xF9DC { - true - } else if let Some(_) = ibm_symbol_encode(bmp) { - true - } else if let Some(_) = jis0208_symbol_encode(bmp) { - true - } else { - false - } + // fast-track common punctuation + bmp_minus_space < 3 + || in_inclusive_range16(bmp, 0xFF61, 0xFF9F) + || bmp == 0x2212 + || jis0208_range_encode(bmp).is_some() + || in_inclusive_range16(bmp, 0xFA0E, 0xFA2D) + || bmp == 0xF929 + || bmp == 0xF9DC + || ibm_symbol_encode(bmp).is_some() + || jis0208_symbol_encode(bmp).is_some() } } } @@ -477,10 +462,7 @@ impl Iso2022JpEncoder { } pub fn has_pending_state(&self) -> bool { - match self.state { - Iso2022JpEncoderState::Ascii => false, - _ => true, - } + !matches!(self.state, Iso2022JpEncoderState::Ascii) } pub fn max_buffer_length_from_utf16_without_replacement( diff --git a/src/utf_8.rs b/src/utf_8.rs index bdcc868..07e4efe 100644 --- a/src/utf_8.rs +++ b/src/utf_8.rs @@ -893,6 +893,7 @@ pub fn convert_utf16_to_utf8_partial_tail(src: &[u16], dst: &mut [u8]) -> (usize // Got surrogate if unit_minus_surrogate_start <= (0xDBFF - 0xD800) { // Got high surrogate + #[allow(clippy::branches_sharing_code)] if read >= src.len() { // Unpaired high surrogate unit = 0xFFFD; diff --git a/src/variant.rs b/src/variant.rs index a0032f1..f4b9b12 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -402,9 +402,9 @@ impl VariantEncoding { } pub fn is_single_byte(&self) -> bool { - match *self { - VariantEncoding::SingleByte(_, _, _, _) | VariantEncoding::UserDefined => true, - _ => false, - } + matches!( + *self, + VariantEncoding::SingleByte(_, _, _, _) | VariantEncoding::UserDefined + ) } } diff --git a/src/x_user_defined.rs b/src/x_user_defined.rs index 0d9b90d..e7ac101 100644 --- a/src/x_user_defined.rs +++ b/src/x_user_defined.rs @@ -176,7 +176,7 @@ impl UserDefinedEncoder { destination_handle.write_one(c as u8); continue; } - if c < '\u{F780}' || c > '\u{F7FF}' { + if !('\u{F780}'..='\u{F7FF}').contains(&c) { return ( EncoderResult::Unmappable(c), unread_handle.consumed(),