private static int IndexOfTimePart(string format, int startIndex, string timeParts)
{
Contract.Assert(startIndex >= 0, "startIndex cannot be negative");
Contract.Assert(timeParts.IndexOfAny(new char[] { '\'', '\\' }) == -1, "timeParts cannot include quote characters");
bool inQuote = false;
for (int i = startIndex; i < format.Length; ++i)
{
// See if we have a time Part
if (!inQuote && timeParts.IndexOf(format[i]) != -1)
{
return i;
}
switch (format[i])
{
case '\\':
if (i + 1 < format.Length)
{
++i;
switch (format[i])
{
case '\'':
case '\\':
break;
default:
--i; //backup since we will move over this next
break;
}
}
break;
case '\'':
inQuote = !inQuote;
break;
}
}
return -1;
}