use rust_decimal::Decimal;
pub(crate) fn canonical_iban(s: &str) -> String {
s.chars()
.filter(|c| !c.is_whitespace())
.map(|c| c.to_ascii_uppercase())
.collect()
}
pub(crate) fn canonical_amount(amount: Decimal) -> String {
let mut normalized = amount.round_dp(2);
if normalized.is_zero() {
normalized = Decimal::ZERO;
}
normalized.rescale(2);
normalized.to_string()
}
pub(crate) fn canonical_text(s: &str) -> String {
s.replace(['\r', '\n'], " ").trim().to_owned()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn zero_amount_is_canonicalized() {
assert_eq!(canonical_amount(Decimal::ZERO), "0.00");
assert_eq!(canonical_amount("-0.00".parse().unwrap()), "0.00");
assert_eq!(canonical_amount(Decimal::new(-350, 2)), "-3.50");
}
}