Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/euc_jp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions src/gb18030.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
52 changes: 17 additions & 35 deletions src/iso_2022_jp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)]
Expand All @@ -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()
}
}
}
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/utf_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
2 changes: 1 addition & 1 deletion src/x_user_defined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading