AssetId.parse constructor

AssetId.parse(
  1. String description
)

Parses an AssetId string of the form "package|path/to/asset.txt".

The path will be normalized: any backslashes will be replaced with forward slashes (regardless of host OS) and "." and ".." will be removed where possible.

Implementation

factory AssetId.parse(String description) {
  var parts = description.split('|');
  if (parts.length != 2) {
    throw FormatException('Could not parse "$description".');
  }

  if (parts[0].isEmpty) {
    throw FormatException(
        'Cannot have empty package name in "$description".');
  }

  if (parts[1].isEmpty) {
    throw FormatException('Cannot have empty path in "$description".');
  }

  return AssetId(parts[0], parts[1]);
}