private static bool TryGetParametersEndIndex(string input, ref int parseEndIndex, ref int parameterEndIndex)
{
Debug.Assert(parseEndIndex < input.Length, "Expected string to have at least 1 char");
Debug.Assert(input[parseEndIndex] == ',');
int current = parseEndIndex;
do
{
current++; // skip ',' delimiter
bool separatorFound = false; // ignore value returned by GetNextNonEmptyOrWhitespaceIndex()
current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(input, current, true, out separatorFound);
if (current == input.Length)
{
return true;
}
// Now we have to determine if after ',' we have a list of <name>=<value> pairs that are part of
// the auth scheme parameters OR if we have another auth scheme. Either way, after ',' we expect a
// valid token that is either the <name> in a <name>=<value> pair OR <scheme> of another scheme.
int tokenLength = HttpRuleParser.GetTokenLength(input, current);
if (tokenLength == 0)
{
return false;
}
current = current + tokenLength;
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
// If we reached the end of the string or the token is followed by anything but '=', then the parsed
// token is another scheme name. The string representing parameters ends before the token (e.g.
// "Digest a=b, c=d, NTLM": return scheme "Digest" with parameters string "a=b, c=d").
if ((current == input.Length) || (input[current] != '='))
{
return true;
}
current++; // skip '=' delimiter
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
int valueLength = NameValueHeaderValue.GetValueLength(input, current);
// After '<name>=' we expect a valid <value> (either token or quoted string)
if (valueLength == 0)
{
return false;
}
// Update parameter end index, since we just parsed a valid <name>=<value> pair that is part of the
// parameters string.
current = current + valueLength;
parameterEndIndex = current - 1; // -1 because 'current' already points to the char after <value>
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
parseEndIndex = current; // this essentially points to parameterEndIndex + whitespace + next char
} while ((current < input.Length) && (input[current] == ','));
return true;
}