difftreelog
chore simplify `builtin_parse_int`
in: master
1 file changed
crates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth50 Ok(str.to_ascii_lowercase())50 Ok(str.to_ascii_lowercase())51}51}5253pub fn repeat(what: Either![IStr, ArrValue], count: i32) {54 joi55}565257#[builtin]53#[builtin]58pub fn builtin_find_substr(pat: IStr, str: IStr) -> Result<ArrValue> {54pub fn builtin_find_substr(pat: IStr, str: IStr) -> Result<ArrValue> {817782#[builtin]78#[builtin]83pub fn builtin_parse_int(raw: IStr) -> Result<f64> {79pub fn builtin_parse_int(raw: IStr) -> Result<f64> {84 let mut chars = raw.chars();85 if let Some(first_char) = chars.next() {80 if let Some(raw) = raw.strip_prefix('-') {86 if first_char == '-' {87 let remaining = chars.as_str();88 if remaining.is_empty() {81 if raw.is_empty() {89 throw!("Integer only consists of a minus");82 throw!("integer only consists of a minus")90 }83 }8491 parse_nat::<10>(remaining).map(|value| -value)85 parse_nat::<10>(raw).map(|value| -value)92 } else {93 parse_nat::<10>(raw.as_str())94 }95 } else {86 } else {87 if raw.is_empty() {96 throw!("Empty decimal integer",);88 throw!("empty integer")89 }9091 parse_nat::<10>(raw.as_str())97 }92 }98}93}9994