mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
clippy: simplify code according to nightly 'byte_char_slices' lint
https://rust-lang.github.io/rust-clippy/master/index.html#/byte_char_slices
This commit is contained in:
parent
84f8b7a98b
commit
471f047a64
6 changed files with 14 additions and 14 deletions
|
@ -623,10 +623,10 @@ fn write_nonprint_to_end<W: Write>(in_buf: &[u8], writer: &mut W, tab: &[u8]) ->
|
||||||
9 => writer.write_all(tab),
|
9 => writer.write_all(tab),
|
||||||
0..=8 | 10..=31 => writer.write_all(&[b'^', byte + 64]),
|
0..=8 | 10..=31 => writer.write_all(&[b'^', byte + 64]),
|
||||||
32..=126 => writer.write_all(&[byte]),
|
32..=126 => writer.write_all(&[byte]),
|
||||||
127 => writer.write_all(&[b'^', b'?']),
|
127 => writer.write_all(b"^?"),
|
||||||
128..=159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]),
|
128..=159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]),
|
||||||
160..=254 => writer.write_all(&[b'M', b'-', byte - 128]),
|
160..=254 => writer.write_all(&[b'M', b'-', byte - 128]),
|
||||||
_ => writer.write_all(&[b'M', b'-', b'^', b'?']),
|
_ => writer.write_all(b"M-^?"),
|
||||||
}
|
}
|
||||||
.unwrap();
|
.unwrap();
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
|
@ -86,7 +86,7 @@ pub fn decode(f: Format, input: &[u8]) -> DecodeResult {
|
||||||
Z85 => {
|
Z85 => {
|
||||||
// The z85 crate implements a padded encoding by using a leading '#' which is otherwise not allowed.
|
// The z85 crate implements a padded encoding by using a leading '#' which is otherwise not allowed.
|
||||||
// We manually check for a leading '#' and return an error ourselves.
|
// We manually check for a leading '#' and return an error ourselves.
|
||||||
if input.starts_with(&[b'#']) {
|
if input.starts_with(b"#") {
|
||||||
return Err(z85::DecodeError::InvalidByte(0, b'#').into());
|
return Err(z85::DecodeError::InvalidByte(0, b'#').into());
|
||||||
} else {
|
} else {
|
||||||
z85::decode(input)?
|
z85::decode(input)?
|
||||||
|
|
|
@ -402,7 +402,7 @@ impl<'a> DigestWriter<'a> {
|
||||||
|
|
||||||
pub fn finalize(&mut self) -> bool {
|
pub fn finalize(&mut self) -> bool {
|
||||||
if self.was_last_character_carriage_return {
|
if self.was_last_character_carriage_return {
|
||||||
self.digest.hash_update(&[b'\r']);
|
self.digest.hash_update(b"\r");
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -433,7 +433,7 @@ impl<'a> Write for DigestWriter<'a> {
|
||||||
// call to `write()`.
|
// call to `write()`.
|
||||||
let n = buf.len();
|
let n = buf.len();
|
||||||
if self.was_last_character_carriage_return && n > 0 && buf[0] != b'\n' {
|
if self.was_last_character_carriage_return && n > 0 && buf[0] != b'\n' {
|
||||||
self.digest.hash_update(&[b'\r']);
|
self.digest.hash_update(b"\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, find all occurrences of "\r\n", inputting the slice
|
// Next, find all occurrences of "\r\n", inputting the slice
|
||||||
|
@ -491,15 +491,15 @@ mod tests {
|
||||||
// Writing "\r" in one call to `write()`, and then "\n" in another.
|
// Writing "\r" in one call to `write()`, and then "\n" in another.
|
||||||
let mut digest = Box::new(Md5::new()) as Box<dyn Digest>;
|
let mut digest = Box::new(Md5::new()) as Box<dyn Digest>;
|
||||||
let mut writer_crlf = DigestWriter::new(&mut digest, false);
|
let mut writer_crlf = DigestWriter::new(&mut digest, false);
|
||||||
writer_crlf.write_all(&[b'\r']).unwrap();
|
writer_crlf.write_all(b"\r").unwrap();
|
||||||
writer_crlf.write_all(&[b'\n']).unwrap();
|
writer_crlf.write_all(b"\n").unwrap();
|
||||||
writer_crlf.finalize();
|
writer_crlf.finalize();
|
||||||
let result_crlf = digest.result_str();
|
let result_crlf = digest.result_str();
|
||||||
|
|
||||||
// We expect "\r\n" to be replaced with "\n" in text mode on Windows.
|
// We expect "\r\n" to be replaced with "\n" in text mode on Windows.
|
||||||
let mut digest = Box::new(Md5::new()) as Box<dyn Digest>;
|
let mut digest = Box::new(Md5::new()) as Box<dyn Digest>;
|
||||||
let mut writer_lf = DigestWriter::new(&mut digest, false);
|
let mut writer_lf = DigestWriter::new(&mut digest, false);
|
||||||
writer_lf.write_all(&[b'\n']).unwrap();
|
writer_lf.write_all(b"\n").unwrap();
|
||||||
writer_lf.finalize();
|
writer_lf.finalize();
|
||||||
let result_lf = digest.result_str();
|
let result_lf = digest.result_str();
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ macro_rules! test_digest {
|
||||||
// The asterisk indicates that the digest was computed in
|
// The asterisk indicates that the digest was computed in
|
||||||
// binary mode.
|
// binary mode.
|
||||||
let n = expected.len();
|
let n = expected.len();
|
||||||
let expected = [&expected[..n - 3], &[b' ', b'-', b'\n']].concat();
|
let expected = [&expected[..n - 3], b" -\n"].concat();
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&[DIGEST_ARG, BITS_ARG, "-t"])
|
.args(&[DIGEST_ARG, BITS_ARG, "-t"])
|
||||||
.pipe_in("a\r\nb\r\nc\r\n")
|
.pipe_in("a\r\nb\r\nc\r\n")
|
||||||
|
|
|
@ -1434,8 +1434,8 @@ fn check_complement_set2_too_big() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_truncate_non_utf8_set() {
|
fn test_truncate_non_utf8_set() {
|
||||||
let stdin = &[b'\x01', b'a', b'm', b'p', 0xfe_u8, 0xff_u8];
|
let stdin = b"\x01amp\xfe\xff";
|
||||||
let set1 = OsStr::from_bytes(&[b'a', 0xfe_u8, 0xff_u8, b'z']);
|
let set1 = OsStr::from_bytes(b"a\xfe\xffz"); // spell-checker:disable-line
|
||||||
let set2 = OsStr::from_bytes(b"01234");
|
let set2 = OsStr::from_bytes(b"01234");
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
|
@ -59,7 +59,7 @@ static ALREADY_RUN: &str = " you have already run this UCommand, if you want to
|
||||||
static MULTIPLE_STDIN_MEANINGLESS: &str = "Ucommand is designed around a typical use case of: provide args and input stream -> spawn process -> block until completion -> return output streams. For verifying that a particular section of the input stream is what causes a particular behavior, use the Command type directly.";
|
static MULTIPLE_STDIN_MEANINGLESS: &str = "Ucommand is designed around a typical use case of: provide args and input stream -> spawn process -> block until completion -> return output streams. For verifying that a particular section of the input stream is what causes a particular behavior, use the Command type directly.";
|
||||||
|
|
||||||
static NO_STDIN_MEANINGLESS: &str = "Setting this flag has no effect if there is no stdin";
|
static NO_STDIN_MEANINGLESS: &str = "Setting this flag has no effect if there is no stdin";
|
||||||
static END_OF_TRANSMISSION_SEQUENCE: &[u8] = &[b'\n', 0x04];
|
static END_OF_TRANSMISSION_SEQUENCE: &[u8] = b"\n\x04";
|
||||||
|
|
||||||
pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_coreutils");
|
pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_coreutils");
|
||||||
pub const PATH: &str = env!("PATH");
|
pub const PATH: &str = env!("PATH");
|
||||||
|
@ -3081,7 +3081,7 @@ mod tests {
|
||||||
let result = TestScenario::new("echo").ucmd().arg("Hello world").run();
|
let result = TestScenario::new("echo").ucmd().arg("Hello world").run();
|
||||||
|
|
||||||
result.stdout_str_check(|stdout| stdout.ends_with("world\n"));
|
result.stdout_str_check(|stdout| stdout.ends_with("world\n"));
|
||||||
result.stdout_check(|stdout| stdout.get(0..2).unwrap().eq(&[b'H', b'e']));
|
result.stdout_check(|stdout| stdout.get(0..2).unwrap().eq(b"He"));
|
||||||
result.no_stderr();
|
result.no_stderr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3096,7 +3096,7 @@ mod tests {
|
||||||
));
|
));
|
||||||
|
|
||||||
result.stderr_str_check(|stderr| stderr.ends_with("world\n"));
|
result.stderr_str_check(|stderr| stderr.ends_with("world\n"));
|
||||||
result.stderr_check(|stderr| stderr.get(0..2).unwrap().eq(&[b'H', b'e']));
|
result.stderr_check(|stdout| stdout.get(0..2).unwrap().eq(b"He"));
|
||||||
result.no_stdout();
|
result.no_stdout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue