Skip to content

Commit

Permalink
Merge pull request #345 from fox0/iconv
Browse files Browse the repository at this point in the history
iconv: Fix clippy
  • Loading branch information
jgarzik authored Oct 18, 2024
2 parents 83f986d + f4d9ca9 commit 05d848d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions i18n/iconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ impl<R: Read> IntoIterator for CircularBuffer<R> {
}
}

#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(EnumString, EnumIter, Debug, PartialEq, Display)]
#[strum(serialize_all = "SCREAMING-KEBAB-CASE")]
#[allow(non_camel_case_types)]
enum Encodings {
ASCII,
UTF_8,
Expand Down Expand Up @@ -427,7 +427,7 @@ fn charmap_conversion(
for byte in input {
buffer.push(byte);
let mut found = false;
for (_, entry) in &from.entries {
for entry in from.entries.values() {
if buffer.starts_with(&entry.encoding) {
if let Some(to_entry) = to
.entries
Expand Down
7 changes: 4 additions & 3 deletions i18n/iconv_lib/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
) -> Box<dyn Iterator<Item = u32>> {
let mut position = 0;

let iter = std::iter::from_fn(move || {
while let Some(code_point) = input.next() {
let iter = iter::from_fn(move || {
for code_point in input.by_ref() {
position += 1;
if code_point <= 127 {
return Some(code_point as u32);
Expand All @@ -43,8 +43,9 @@ pub fn from_ucs4<I: Iterator<Item = u32> + 'static>(
suppress_error: bool,
) -> Box<dyn Iterator<Item = u8>> {
let mut position = 0;

let iter = iter::from_fn(move || {
while let Some(code_point) = input.next() {
for code_point in input.by_ref() {
position += 1;
if code_point <= 127 {
return Some(code_point as u8);
Expand Down
8 changes: 4 additions & 4 deletions i18n/iconv_lib/utf_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
return Some(code_point);

// 2 bytes
} else if byte >= 0xC0 && byte <= 0xDF {
} else if (0xC0..=0xDF).contains(&byte) {
if buffer.len() < 2 {
let add_bytes = input.by_ref().take(2 - buffer.len()).collect::<Vec<_>>();
buffer.extend(add_bytes);
Expand Down Expand Up @@ -76,7 +76,7 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
return Some(code_point);

// 3 bytes
} else if byte >= 0xE0 && byte <= 0xEF {
} else if (0xE0..=0xEF).contains(&byte) {
if buffer.len() < 3 {
let add_bytes = input.by_ref().take(3 - buffer.len()).collect::<Vec<_>>();
buffer.extend(add_bytes);
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
return Some(code_point);

// 4 bytes
} else if byte >= 0xF0 && byte <= 0xF4 {
} else if (0xF0..=0xF4).contains(&byte) {
if buffer.len() < 4 {
let add_bytes = input.by_ref().take(4 - buffer.len()).collect::<Vec<_>>();
buffer.extend(add_bytes);
Expand Down Expand Up @@ -155,7 +155,7 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
| ((buffer[1] as u32 & 0x3F) << 12)
| ((buffer[2] as u32 & 0x3F) << 6)
| (buffer[3] as u32 & 0x3F);
if code_point > 0x10FFFF || code_point < 0x10000 {
if !(0x10000..=0x10FFFF).contains(&code_point) {
if omit_invalid {
buffer.drain(0..4);
continue;
Expand Down

0 comments on commit 05d848d

Please sign in to comment.