`defmt_parser`: Simplify `fn parse_range(...)`
@@ -128,33 +128,31 @@ impl Default for Type {
}
}
-fn is_digit(c: Option<char>) -> bool {
- matches!(c.unwrap_or('\0'), '0'..='9')
-}
-
fn parse_range(mut s: &str) -> Option<(Range<u8>, usize /* consumed */)> {
+ // consume first number
let start_digits = s
.as_bytes()
.iter()
- .take_while(|b| is_digit(Some(**b as char)))
+ .take_while(|b| (**b as char).is_ascii_digit())
.count();
let start = s[..start_digits].parse().ok()?;
+
+ // next two `char`s should be `..`
if &s[start_digits..start_digits + 2] != ".." {
return None;
}
s = &s[start_digits + 2..];
+
+ // consume second number
let end_digits = s
.as_bytes()
.iter()
- .take_while(|b| is_digit(Some(**b as char)))
+ .take_while(|b| (**b as char).is_ascii_digit())
.count();
let end = s[..end_digits].parse().ok()?;
- if end <= start {
- return None;
- }
-
- if start >= 128 || end > 128 {
+ // check for faulty state
+ if end <= start || start >= 128 || end > 128 {
return None;
}
