MediaType.fromText constructor

MediaType.fromText(
  1. String text
)

Creates a media type from the specified text

The text must use the top/sub structure, e.g. 'text/plain'

Implementation

factory MediaType.fromText(String text) {
  final lcText = text.toLowerCase();
  final splitPos = lcText.indexOf('/');
  if (splitPos != -1) {
    final topText = lcText.substring(0, splitPos);
    final top = _topLevelByMimeName[topText] ?? MediaToptype.other;
    final sub = _subtypesByMimeType[lcText] ?? MediaSubtype.other;

    return MediaType(lcText, top, sub);
  } else {
    final top = _topLevelByMimeName[lcText] ?? MediaToptype.other;

    return MediaType(lcText, top, MediaSubtype.other);
  }
}