parse method

  1. @override
num parse(
  1. String input
)
override

Parses input and returns the numeric value.

Throws FormatException when input cannot be parsed by this codec.

Implementation

@override
num parse(String input) {
  final trimmed = input.trim();
  if (trimmed.isEmpty) {
    throw FormatException('Expected a compact number.', input);
  }

  final match = _unitMatcher.match(trimmed);
  final parsedNumber = style.parse(match.number);
  if (!parsedNumber.isFinite && match.number != trimmed) {
    throw FormatException(
      'Special compact values must not use units.',
      input,
    );
  }
  return normalizeNum(parsedNumber * match.unit.scale);
}