private static bool TryReadDate(string input, ref int current, out DateTimeOffset? date)
{
date = null;
// Make sure we have at least one whitespace between <text> and <date> (if we have <date>)
int whitespaceLength = HttpRuleParser.GetWhitespaceLength(input, current);
current = current + whitespaceLength;
// Read <date> in '<code> <agent> <text> ["<date>"]'
if ((current < input.Length) && (input[current] == '"'))
{
if (whitespaceLength == 0)
{
return false; // we have characters after <text> but they were not separated by a whitespace
}
current++; // skip opening '"'
// Find the closing '"'
int dateStartIndex = current;
while (current < input.Length)
{
if (input[current] == '"')
{
break;
}
current++;
}
if ((current == input.Length) || (current == dateStartIndex))
{
return false; // we couldn't find the closing '"' or we have an empty quoted string.
}
DateTimeOffset temp;
if (!HttpRuleParser.TryStringToDate(input.Substring(dateStartIndex, current - dateStartIndex), out temp))
{
return false;
}
date = temp;
current++; // skip closing '"'
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
}
return true;
}