more bounds checking

This commit is contained in:
ConnorSkees 2020-02-16 15:34:21 -05:00
parent 4238124344
commit 048ab562b2

View File

@ -100,7 +100,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
v => return Err(format!("$color: {} is not a color.", v).into()), v => return Err(format!("$color: {} is not a color.", v).into()),
}; };
let amount = match arg!(args, 1, "amount").eval() { let amount = match arg!(args, 1, "amount").eval() {
Value::Dimension(n, _) => n / Number::from(100), Value::Dimension(n, u) => bound!("amount", n, u, 0, 100) / Number::from(100),
v => return Err(format!("$amount: {} is not a number.", v).into()) v => return Err(format!("$amount: {} is not a number.", v).into())
}; };
Ok(Value::Color(color.darken(amount))) Ok(Value::Color(color.darken(amount)))
@ -112,7 +112,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
v => return Err(format!("$color: {} is not a color.", v).into()), v => return Err(format!("$color: {} is not a color.", v).into()),
}; };
let amount = match arg!(args, 1, "amount").eval() { let amount = match arg!(args, 1, "amount").eval() {
Value::Dimension(n, _) => n / Number::from(100), Value::Dimension(n, u) => bound!("amount", n, u, 0, 100) / Number::from(100),
v => return Err(format!("$amount: {} is not a number.", v).into()) v => return Err(format!("$amount: {} is not a number.", v).into())
}; };
Ok(Value::Color(color.saturate(amount))) Ok(Value::Color(color.saturate(amount)))
@ -124,7 +124,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
v => return Err(format!("$color: {} is not a color.", v).into()), v => return Err(format!("$color: {} is not a color.", v).into()),
}; };
let amount = match arg!(args, 1, "amount").eval() { let amount = match arg!(args, 1, "amount").eval() {
Value::Dimension(n, _) => n / Number::from(100), Value::Dimension(n, u) => bound!("amount", n, u, 0, 100) / Number::from(100),
v => return Err(format!("$amount: {} is not a number.", v).into()) v => return Err(format!("$amount: {} is not a number.", v).into())
}; };
Ok(Value::Color(color.desaturate(amount))) Ok(Value::Color(color.desaturate(amount)))