feat: ignore and add back single equal sign

more than one is likely a user mistake and a panic still makes sense

should also add back '&' in the same way, if applicable
This commit is contained in:
electria 2026-07-24 21:50:58 -07:00
commit 704ef81816
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -18,9 +18,33 @@ fn main() {
}
};
println!("{}", parse_and_calc_humanreadable(input));
}
pub fn parse_and_calc_humanreadable(mut input: String) -> String {
let should_add_back_equals = if let Some((i, _)) = input
.chars()
.enumerate()
.filter(|(_, c)| !matches!(c, ' ' | '&' | '\n'))
.find(|(_, c)| *c == '=')
{
input.remove(i);
true
} else {
false
};
let result = parse_and_calc(&input);
println!("{result:.0$}", get_significant_digits(&result));
format!(
"{0}{result:.1$}",
if should_add_back_equals { "= " } else { "" },
get_significant_digits(&result),
)
}
#[test]
fn test_equals_readdition() {
assert_eq!(parse_and_calc_humanreadable(" = 11".into()), "= 11");
}
pub fn parse_and_calc(s: &str) -> Float {