Canonicalize to longer version of prefix

This commit is contained in:
Tiffany Bennett 2016-08-25 21:57:53 -04:00
parent 4049a8c922
commit eb185656dd
2 changed files with 8 additions and 2 deletions

View file

@ -212,9 +212,15 @@ impl Context {
return Some(v)
}
}
for &(ref pre, _) in &self.prefixes {
for &(ref pre, ref val) in &self.prefixes {
if name.starts_with(pre) {
if let Some(v) = self.canonicalize(&name[pre.len()..]) {
let mut pre = pre;
for &(ref other, ref otherval) in &self.prefixes {
if other.len() > pre.len() && val == otherval {
pre = other;
}
}
return Some(format!("{}{}", pre, v))
}
}

View file

@ -18,7 +18,7 @@ pub type Dim = Rc<String>;
pub type Unit = BTreeMap<Dim, i64>;
/// The basic representation of a number with a unit.
#[derive(Clone)]
#[derive(Clone, PartialEq, Eq)]
pub struct Number(pub Num, pub Unit);
fn one() -> Mpq {