refactor: avoid extra owned string
I think this is more readable, too
This commit is contained in:
parent
acc49edd31
commit
5cdfbfea5e
1 changed files with 5 additions and 5 deletions
|
|
@ -3,14 +3,14 @@ use rug::Float;
|
|||
use crate::nodes::{self, Error};
|
||||
|
||||
pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
|
||||
let (prefix, input) = input
|
||||
let (prefix, deliminator, input) = input
|
||||
.rsplit_once('=')
|
||||
.map(|(p, i)| (p.to_owned() + "= ", i))
|
||||
.map(|(p, i)| (p, "= ", i))
|
||||
.unwrap_or_else(|| {
|
||||
input
|
||||
.rsplit_once('&')
|
||||
.map(|(p, i)| (p.to_owned() + "& ", i))
|
||||
.unwrap_or((String::new(), input))
|
||||
.map(|(p, i)| (p, "& ", i))
|
||||
.unwrap_or(("", "", input))
|
||||
});
|
||||
|
||||
// no need to remove the character here,
|
||||
|
|
@ -33,7 +33,7 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
|
|||
});
|
||||
|
||||
Ok(format!(
|
||||
"{prefix}{result:.display_digits$}{}",
|
||||
"{prefix}{deliminator}{result:.display_digits$}{}",
|
||||
if should_add_back_backslash { " \\" } else { "" }
|
||||
)
|
||||
.replace('e', " * 10^"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue