mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix nasty string boundary bug 🏗
This commit is contained in:
parent
a87937d0c4
commit
b8620121a6
25
src/size.rs
25
src/size.rs
@ -352,21 +352,18 @@ impl FromStr for Size {
|
|||||||
type Err = ParseSizeError;
|
type Err = ParseSizeError;
|
||||||
|
|
||||||
fn from_str(src: &str) -> Result<Size, ParseSizeError> {
|
fn from_str(src: &str) -> Result<Size, ParseSizeError> {
|
||||||
if src.len() < 2 {
|
let func = match () {
|
||||||
return Err(ParseSizeError);
|
_ if src.ends_with("pt") => Size::pt,
|
||||||
}
|
_ if src.ends_with("mm") => Size::mm,
|
||||||
|
_ if src.ends_with("cm") => Size::cm,
|
||||||
let value = src[..src.len() - 2]
|
_ if src.ends_with("in") => Size::inches,
|
||||||
.parse::<f32>()
|
|
||||||
.map_err(|_| ParseSizeError)?;
|
|
||||||
|
|
||||||
Ok(match &src[src.len() - 2..] {
|
|
||||||
"pt" => Size::pt(value),
|
|
||||||
"mm" => Size::mm(value),
|
|
||||||
"cm" => Size::cm(value),
|
|
||||||
"in" => Size::inches(value),
|
|
||||||
_ => return Err(ParseSizeError),
|
_ => return Err(ParseSizeError),
|
||||||
})
|
};
|
||||||
|
|
||||||
|
Ok(func(src[..src.len() - 2]
|
||||||
|
.parse::<f32>()
|
||||||
|
.map_err(|_| ParseSizeError)?))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user