Allow parsing compression ratios without a colon
This commit is contained in:
parent
35c6b97ade
commit
5010ce5e1a
|
@ -49,15 +49,22 @@ pub fn v2s_compression_ratio(digits: usize) -> Arc<dyn Fn(f32) -> String + Send
|
|||
}
|
||||
|
||||
/// Parse a `x:y` compression ratio back to a floating point number. Used in conjunction with
|
||||
/// [`v2s_compression_ratio()`].
|
||||
/// [`v2s_compression_ratio()`]. Plain numbers are parsed directly for UX's sake.
|
||||
pub fn s2v_compression_ratio() -> Arc<dyn Fn(&str) -> Option<f32> + Send + Sync> {
|
||||
Arc::new(|string| {
|
||||
let (numerator, denominator) = string.trim().split_once(':')?;
|
||||
let string = string.trim();
|
||||
string
|
||||
.trim()
|
||||
.split_once(':')
|
||||
.and_then(|(numerator, denominator)| {
|
||||
let numerator: f32 = numerator.trim().parse().ok()?;
|
||||
let denominator: f32 = denominator.trim().parse().ok()?;
|
||||
|
||||
Some(numerator / denominator)
|
||||
})
|
||||
// Just parse the value directly if it doesn't contain a colon
|
||||
.or_else(|| string.parse().ok())
|
||||
})
|
||||
}
|
||||
|
||||
/// Turn an `f32` value from voltage gain to decibels using the semantics described in
|
||||
|
|
Loading…
Reference in a new issue