contains method

bool contains(
  1. MediaType? other
)

Returns whether the given other media type is included in this media type.

For example, text/html contains text/html;charset=utf-8.

  • other must match the parameters in the parameters property, but extra parameters are ignored.
  • Order of parameters is ignored.
  • Wildcards are supported, meaning that image/* contains image/png and */* contains everything.

Implementation

bool contains(MediaType? other) {
  if (other == null ||
      (type != "*" && type != other.type) ||
      (subtype != "*" && subtype != other.subtype)) {
    return false;
  }
  Set<String> paramsSet =
      parameters.entries.map((e) => "${e.key}=${e.value}").toSet();
  Set<String> otherParamsSet =
      other.parameters.entries.map((e) => "${e.key}=${e.value}").toSet();
  return otherParamsSet.containsAll(paramsSet);
}