public static void ParseContentType()

in src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs [3085:3119]


        public static void ParseContentType(string contentType, out string mediaType, out Encoding encoding)
        {
            var splitted = contentType.Split(';');
            mediaType = splitted[0];
            if (!MediaTypeHeaderValue.TryParse(mediaType, out _))
            {
                throw new ArgumentException($"{nameof(contentType)} is not valid.");
            }

            encoding = Encoding.UTF8;

            if (splitted.Count() == 2)
            {
                var matches = Regex.Matches(splitted[1], @"charset\s*=[\s""']*([^\s""']*)", RegexOptions.IgnoreCase);
                if (matches.Count > 0)
                {
                    try
                    {
                        encoding = Encoding.GetEncoding(matches[0].Groups[1].Value);
                    }
                    catch
                    {
                        throw new ArgumentException($"{nameof(contentType)} is not valid.");
                    }
                }
                else
                {
                    throw new ArgumentException($"{nameof(contentType)} is not valid.");
                }
            }
            else if (splitted.Count() > 2)
            {
                throw new ArgumentException($"{nameof(contentType)} is not valid.");
            }
        }