isMimeType method Null safety

  1. @Since("2.17")
bool isMimeType(
  1. String mimeType
)

Whether the UriData.mimeType is equal to mimeType.

Compares the data: URI's MIME type to mimeType with a case- insensitive comparison which ignores the case of ASCII letters.

An empty mimeType is considered equivalent to text/plain, both in the mimeType argument and in the data: URI itself.

Implementation

@Since("2.17")
bool isMimeType(String mimeType) {
  int start = _separatorIndices[0] + 1;
  int end = _separatorIndices[1];
  if (start == end) {
    return mimeType.isEmpty ||
        identical(mimeType, "text/plain") ||
        _caseInsensitiveEquals(mimeType, "text/plain");
  }
  if (mimeType.isEmpty) mimeType = "text/plain";
  return (mimeType.length == end - start) &&
      _caseInsensitiveStartsWith(mimeType, _text, start);
}