mirror of
https://github.com/sharkdp/bat
synced 2026-08-10 20:01:45 +00:00
Reduce nesting in if blocks by short circuiting
This commit is contained in:
committed by
Martin Nordholts
parent
9124271eaf
commit
372e42f350
+6
-6
@@ -11,13 +11,13 @@ pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<usize> {
|
||||
}
|
||||
|
||||
fn parse_less_version(output: &[u8]) -> Option<usize> {
|
||||
if output.starts_with(b"less ") {
|
||||
let version = std::str::from_utf8(&output[5..]).ok()?;
|
||||
let end = version.find(|c: char| !c.is_ascii_digit())?;
|
||||
version[..end].parse::<usize>().ok()
|
||||
} else {
|
||||
None
|
||||
if !output.starts_with(b"less ") {
|
||||
return None;
|
||||
}
|
||||
|
||||
let version = std::str::from_utf8(&output[5..]).ok()?;
|
||||
let end = version.find(|c: char| !c.is_ascii_digit())?;
|
||||
version[..end].parse::<usize>().ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user