int IndexOfAnyEscaped (char[] ch, string value, char? escape, int startIdx)
{
if (escape == null)
return value.IndexOfAny(ch, startIdx);
int idx = 0, nextStart = startIdx;
do
{
idx = ch.Length == 1 ? value.IndexOf (ch[0], nextStart) : value.IndexOfAny (ch, nextStart);
nextStart = idx + 1;
// If no good match, return; otherwise, check for escape characters
if (idx < 0 || idx >= value.Length)
break;
else
{
// We need to handle repetitions. If there are an odd number of escape characters behind us, we
// are escaped; if an even number, we aren't escaped.
int numEscapes = 0;
for (int i = idx - 1; i >=0 && value [i] == escape.Value; i--)
{
++numEscapes;
}
if (numEscapes % 2 == 0)
break;
}
}
while (true);
return idx;
}