internal static int GetProductLength(string input, int startIndex, out ProductHeaderValue parsedValue)
{
Debug.Assert(startIndex >= 0);
parsedValue = null;
if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
{
return 0;
}
// Parse the name string: <name> in '<name>/<version>'.
int nameLength = HttpRuleParser.GetTokenLength(input, startIndex);
if (nameLength == 0)
{
return 0;
}
ProductHeaderValue result = new ProductHeaderValue();
result._name = input.Substring(startIndex, nameLength);
int current = startIndex + nameLength;
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
if ((current == input.Length) || (input[current] != '/'))
{
parsedValue = result;
return current - startIndex;
}
current++; // Skip '/' delimiter.
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
// Parse the name string: <version> in '<name>/<version>'.
int versionLength = HttpRuleParser.GetTokenLength(input, current);
if (versionLength == 0)
{
return 0; // If there is a '/' separator it must be followed by a valid token.
}
result._version = input.Substring(current, versionLength);
current = current + versionLength;
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
parsedValue = result;
return current - startIndex;
}