validateCanonicalUnits method

String validateCanonicalUnits(
  1. String unit,
  2. String canonical
)

Implementation

String validateCanonicalUnits(String unit, String canonical) {
  assert(unit.isNotEmpty,
      paramError('validate', 'unit', 'must not be null or empty'));
  assert(
      canonical.isNotEmpty,
      paramError('validateCanonicalUnits', 'canonical',
          'must not be null or empty'));

  try {
    final Term term = ExpressionParser(model).parse(unit);
    final Canonical can = Converter(model, handlers).convert(term);
    final String cu = ExpressionComposer().composeCanonical(can, false);
    if (canonical != cu) {
      return 'unit $unit has the base units $cu, not $canonical as required.';
    }
    return '';
  } catch (e) {
    return e.toString();
  }
}