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
8 changes: 2 additions & 6 deletions src/uu/date/src/format_modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ struct ParsedSpec<'a> {
/// valid specifier follows.
fn parse_format_spec(s: &str) -> Option<ParsedSpec<'_>> {
let bytes = s.as_bytes();
if bytes.first() != Some(&b'%') {
return None;
}
bytes.first().filter(|b| *b == &b'%')?;

let mut pos = 1;

Expand All @@ -134,9 +132,7 @@ fn parse_format_spec(s: &str) -> Option<ParsedSpec<'_>> {
while bytes.get(pos) == Some(&b':') && pos - spec_start < 3 {
pos += 1;
}
if bytes.get(pos).is_none_or(|c| !c.is_ascii_alphabetic()) {
return None;
}
bytes.get(pos).filter(|c| c.is_ascii_alphabetic())?;
pos += 1;
let spec = &s[spec_start..pos];

Expand Down
8 changes: 4 additions & 4 deletions src/uu/fmt/src/parasplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ impl Iterator for FileLines<'_> {

fn next(&mut self) -> Option<Line> {
let mut buf = Vec::new();
match self.reader.read_until(b'\n', &mut buf) {
Ok(0) | Err(_) => return None,
Ok(_) => {}
}
self.reader
.read_until(b'\n', &mut buf)
.ok()
.filter(|n| *n > 0)?;
if buf.ends_with(b"\n") {
buf.pop();
if buf.ends_with(b"\r") {
Expand Down
13 changes: 7 additions & 6 deletions src/uucore/src/lib/features/checksum/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ impl LineFormat {
// find the next parenthesis using byte search (not next whitespace) because openssl's
// tagged format does not put a space before (filename)

let par_idx = rest.iter().position(|&b| b == b'(')?;
// If the parenthesis is the first character (minus whitespace, which has already been stripped out), then,
// it's not a validly formatted line.
if par_idx == 0 {
return None;
}
let par_idx = rest
.iter()
.position(|&b| b == b'(')
// If the parenthesis is the first character (minus whitespace, which has already been stripped out), then,
// it's not a validly formatted line.
.filter(|b| *b != 0)?;

let sub_case = if rest[par_idx - 1] == b' ' {
SubCase::Posix
} else {
Expand Down
8 changes: 3 additions & 5 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,13 +1099,11 @@ fn run_df_with_masked_proc(args: &str) -> Option<(bool, String, String)> {
use std::process::Command;

// Check if user namespaces are available
if !Command::new("unshare")
Command::new("unshare")
.args(["-rm", "true"])
.status()
.is_ok_and(|s| s.success())
{
return None;
}
.ok()
.filter(std::process::ExitStatus::success)?;

let df_path = TestScenario::new("df").bin_path.clone();
let output = Command::new("unshare")
Expand Down
12 changes: 4 additions & 8 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,8 @@ fn get_system_abmon(locale: &str) -> Option<Vec<String>> {
.env("LC_ALL", locale)
.arg("abmon")
.output()
.ok()?;
if !output.status.success() {
return None;
}
.ok()
.filter(|s| s.status.success())?;
let text = String::from_utf8(output.stdout).ok()?;
let months: Vec<String> = text
.trim()
Expand Down Expand Up @@ -2077,10 +2075,8 @@ fn test_human_numeric_blank_thousands_sep_locale() {
.arg("thousands_sep")
.env("LC_ALL", locale)
.output()
.ok()?;
if !output.status.success() {
return None;
}
.ok()
.filter(|s| s.status.success())?;
let sep = String::from_utf8_lossy(&output.stdout);
let sep = sep.trim_end_matches(&['\n', '\r'][..]);
if sep.is_empty() || sep.len() != 1 || !sep.chars().all(char::is_whitespace) {
Expand Down
Loading