Cleanup code again
rustfmt is cringe
This commit is contained in:
parent
3cbb97e5b3
commit
f936a5a093
39
src/main.rs
39
src/main.rs
|
@ -88,10 +88,10 @@ fn assert_trailing_leading(s: &str) -> Result<()> {
|
|||
|
||||
fn is_cif_number(num: &str, bytes_per_pixel: u32) -> Result<ArrayVec<&str, 4_usize>> {
|
||||
let split = num.split(';').collect::<ArrayVec<_, 4>>();
|
||||
if split.len() != bytes_per_pixel as usize {
|
||||
return Err(InvalidPixelError(num.to_string()))
|
||||
} else {
|
||||
if split.len() == bytes_per_pixel as usize {
|
||||
Ok(split)
|
||||
} else {
|
||||
Err(InvalidPixelError(num.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,7 @@ fn unfuck_color_type(color_type: &str) -> Result<ColorType> {
|
|||
Ok(color_type)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)] // bruh
|
||||
fn decoder(inputfile: &str, outputfile: &str) -> Result<()> {
|
||||
let infile = File::open(inputfile)?;
|
||||
let outfile = File::create(outputfile)?;
|
||||
|
@ -230,30 +231,28 @@ fn decoder(inputfile: &str, outputfile: &str) -> Result<()> {
|
|||
if md_head {
|
||||
let split = line.split_ascii_whitespace().collect::<ArrayVec<_, 256>>();
|
||||
if split.len() > 2 {
|
||||
return Err(InvalidMetadataError("Metadata values must not contain line feeds.".to_string()))
|
||||
return Err(InvalidMetadataError(line.to_string()))
|
||||
}
|
||||
md_txt.push_str(&line[8..]);
|
||||
continue
|
||||
} else {
|
||||
md_head = true;
|
||||
let mut buf = ArrayString::<2048>::new();
|
||||
let split = line.split_ascii_whitespace().collect::<ArrayVec<_, 256>>();
|
||||
join_to_arraystring(&split, &mut buf)?;
|
||||
let md_split = buf.splitn(3, ' ').collect::<ArrayVec<_, 3>>();
|
||||
if md_split.len() != 3 {
|
||||
return Err(InvalidMetadataError(line.to_string()))
|
||||
}
|
||||
md_key.push_str(md_split[1]);
|
||||
md_txt.push_str(md_split[2]);
|
||||
continue
|
||||
}
|
||||
md_head = true;
|
||||
let mut buf = ArrayString::<2048>::new();
|
||||
let split = line.split_ascii_whitespace().collect::<ArrayVec<_, 256>>();
|
||||
join_to_arraystring(&split, &mut buf)?;
|
||||
let md_split = buf.splitn(3, ' ').collect::<ArrayVec<_, 3>>();
|
||||
if md_split.len() != 3 {
|
||||
return Err(InvalidMetadataError(line.to_string()))
|
||||
}
|
||||
md_key.push_str(md_split[1]);
|
||||
md_txt.push_str(md_split[2]);
|
||||
continue
|
||||
} else if is_cif_number(&line, bytes_per_pixel).is_err() {
|
||||
md_txt.push_str(&line);
|
||||
continue
|
||||
} else {
|
||||
outpng.add_itxt_chunk(md_key.to_string(), md_txt.to_string())?;
|
||||
break line
|
||||
}
|
||||
outpng.add_itxt_chunk(md_key.to_string(), md_txt.to_string())?;
|
||||
break line
|
||||
}
|
||||
return Err(NoDataError)
|
||||
};
|
||||
|
@ -290,7 +289,7 @@ fn decoder(inputfile: &str, outputfile: &str) -> Result<()> {
|
|||
fn main() {
|
||||
let argv = env::args().skip(1).take(2).collect::<ArrayVec<_, 2>>();
|
||||
if argv.len() != 2 {
|
||||
eprintln!("Invalid usage;\nUsage: zardzewialy-dekoder-cif <input cif file> <output bmp file>");
|
||||
eprintln!("Invalid usage:\nUsage: zardzewialy-dekoder-cif <input cif file> <output bmp file>");
|
||||
process::exit(1);
|
||||
}
|
||||
if let Err(e) = decoder(&argv[0], &argv[1]) {
|
||||
|
|
Loading…
Reference in a new issue