public bool Matches(MediaRangeParameters other)
        {
            var ordered      = this.parameters.OrderBy(x => x.Key);
            var otherOrdered = other.parameters.OrderBy(x => x.Key);

            return(ordered.SequenceEqual(otherOrdered));
        }
        public MediaRange WithCharset(Encoding encoding)
        {
            var parameters = new Dictionary <string, string>(capacity: this.Parameters.Count);

            foreach (var parameter in this.Parameters)
            {
                parameters[parameter.Key] = parameter.Value;
            }

            parameters["charset"] = encoding.WebName;

            var newParameters = new MediaRangeParameters(parameters);

            return(new MediaRange(this.Type, this.SubType, newParameters));
        }
        private static Encoding GetCharset(MediaRangeParameters parameters)
        {
            if (parameters.TryGetValue("charset", out var charset))
            {
                try
                {
                    return(Encoding.GetEncoding(charset));
                }
                catch (ArgumentException)
                {
                    return(null);
                }
            }

            return(null);
        }
        public static MediaRange FromString(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(Wildcard);
            }

            var trimmedValue = value.Trim();

            if (trimmedValue.Length == 0)
            {
                return(Wildcard);
            }

            var valueString     = trimmedValue;
            var parameterString = string.Empty;

            var index = trimmedValue.IndexOf(';');

            if (index != -1)
            {
                valueString     = trimmedValue.Substring(0, index).Trim();
                parameterString = trimmedValue.Substring(index, trimmedValue.Length - index).Trim();
            }

            if (valueString.Equals("*", StringComparison.OrdinalIgnoreCase))
            {
                valueString = "*/*";
            }

            if (!Ranges.TryGetValue(valueString, out var range))
            {
                Ranges.Add(valueString, range = ParseString(valueString));
            }

            if (parameterString.Length == 0)
            {
                return(range);
            }

            return(range.WithParameters(MediaRangeParameters.FromString(parameterString)));
        }
 public MediaRange WithParameters(MediaRangeParameters parameters)
 {
     return(new MediaRange(this.Type, this.SubType, parameters));
 }
 public MediaRange(MediaType type, SubMediaType subType, MediaRangeParameters parameters)
 {
     this.Type       = type;
     this.SubType    = subType;
     this.Parameters = parameters;
 }