mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-29 20:47:32 -06:00
Accept long unit names in FormCalc UnitValue (#4116)
Found while testing crates/js/src/formcalc.rs:2526-2532 (UnitValue per_in table; UnitType at :2510-2516) Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
c32c2ce09f
commit
3ee6a83e09
@@ -2522,10 +2522,10 @@ impl Interp<'_> {
|
||||
let v = parse_num(&s).unwrap_or(0.0);
|
||||
let unit: String = s.trim().chars().skip_while(|c| c.is_ascii_digit() || *c == '.' || *c == '-' || *c == '+').collect();
|
||||
let per_in = |u: &str| match u.trim().to_ascii_lowercase().as_str() {
|
||||
"mm" => 25.4,
|
||||
"cm" => 2.54,
|
||||
"pt" => 72.0,
|
||||
"pc" => 6.0,
|
||||
"mm" | "millimeter" | "millimeters" => 25.4,
|
||||
"cm" | "centimeter" | "centimeters" => 2.54,
|
||||
"pt" | "point" | "points" => 72.0,
|
||||
"pc" | "pica" => 6.0,
|
||||
_ => 1.0,
|
||||
};
|
||||
let target = if to.trim().is_empty() { unit.clone() } else { to };
|
||||
|
||||
@@ -990,6 +990,9 @@ mod formcalc {
|
||||
assert_eq!(calc("Round(PV(100, 0.01, 12), 2)"), "1125.51");
|
||||
assert_eq!(calc(r#"UnitValue("2in", "mm")"#), "50.8");
|
||||
assert_eq!(calc(r#"UnitType("2.5cm")"#), "cm");
|
||||
assert_eq!(calc(r#"UnitValue("72points", "in")"#), "1");
|
||||
assert_eq!(calc(r#"UnitValue("25.4millimeters", "inches")"#), "1");
|
||||
assert_eq!(calc(r#"UnitValue("1in", "points")"#), "72");
|
||||
assert_eq!(calc(r#"Encode("a b&c", "url")"#), "a%20b%26c");
|
||||
assert_eq!(calc(r#"Decode("a%20b", "url")"#), "a b");
|
||||
assert!(go(r#"Get("http://example.com")"#, "form1[0].page1[0].total[0]", "calculate").error.unwrap().contains("network"));
|
||||
|
||||
Reference in New Issue
Block a user