Skip to content

Commit 45dafa5

Browse files
committed
numfmt: deduplicate suffix validation in split_mergeable_suffix
The two match arms for length 1 and length 2 had identical RawSuffix::try_from checks. Unify into a single check after a boolean guard.
1 parent 224b93e commit 45dafa5

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

src/uu/numfmt/src/format.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,18 @@ fn split_mergeable_suffix<'a>(s: &'a str, options: &NumfmtOptions) -> Option<(&'
256256
return None;
257257
}
258258

259-
match field.len() {
260-
1 => {
261-
let _ = field
262-
.chars()
263-
.next()
264-
.filter(|c| RawSuffix::try_from(c).is_ok())?;
265-
}
266-
2 if field.ends_with('i') => {
267-
let _ = field
268-
.chars()
269-
.next()
270-
.filter(|c| RawSuffix::try_from(c).is_ok())?;
271-
}
272-
_ => return None,
259+
let is_suffix = match field.len() {
260+
1 => true,
261+
2 => field.ends_with('i'),
262+
_ => false,
263+
};
264+
if !is_suffix {
265+
return None;
273266
}
267+
field
268+
.chars()
269+
.next()
270+
.filter(|c| RawSuffix::try_from(c).is_ok())?;
274271

275272
Some((prefix, field))
276273
}

0 commit comments

Comments
 (0)