public static string ParseHeaderAttribute(string header, string attribute)
{
if (header == null)
return null;
int i;
int headerLength = header.Length;
int attrLength = attribute.Length;
int start = 1;
while (start < headerLength)
{
start = CultureInfo.InvariantCulture.CompareInfo.IndexOf(header, attribute, start, CompareOptions.IgnoreCase);
if ((start < 0) || ((start + attrLength) >= headerLength))
break;
char c = header[start - 1];
char c2 = header[start + attrLength];
if ((((c == ';') || (c == ',')) || char.IsWhiteSpace(c)) && ((c2 == '=') || char.IsWhiteSpace(c2)))
break;
start += attrLength;
}
if ((start < 0) || (start >= headerLength))
return null;
start += attrLength;
while ((start < headerLength) && char.IsWhiteSpace(header[start]))
start++;
if ((start >= headerLength) || (header[start] != '='))
return null;
start++;
while ((start < headerLength) && char.IsWhiteSpace(header[start]))
start++;
if (start >= headerLength)
return null;
if ((start < headerLength) && (header[start] == '"'))
{
if (start == (headerLength - 1))
return null;
i = header.IndexOf('"', start + 1);
if ((i < 0) || (i == (start + 1)))
return null;
return header.Substring(start + 1, (i - start) - 1).Trim();
}
i = start;
while (i < headerLength)
{
if ((header[i] == ' ') || (header[i] == ','))
break;
i++;
}
if (i == start)
return null;
return header.Substring(start, i - start).Trim();
}