Cas.parse constructor

Cas.parse(
  1. String value
)

Parses the string representation of a Cas as returned by toString.

Implementation

factory Cas.parse(String value) {
  Never throwFormatException() =>
      throw FormatException('Invalid CAS string value', value);

  if (value.length != 18 || !value.startsWith('0x')) {
    throwFormatException();
  }

  try {
    final hexDigits = value.substring(2);
    final higher = int.parse(hexDigits.substring(0, 8), radix: 16);
    final lower = int.parse(hexDigits.substring(8), radix: 16);
    return Cas._(higher << 32 | lower);
  } on FormatException {
    throwFormatException();
  }
}