internal Match Scan(Regex regex, String text, int textbeg, int textend, int textstart, int prevlen, bool quick, TimeSpan timeout)
{
int bump;
int stoppos;
bool initted = false;
// We need to re-validate timeout here because Scan is historically protected and
// thus there is a possibility it is called from user code:
Regex.ValidateMatchTimeout(timeout);
_ignoreTimeout = (Regex.InfiniteMatchTimeout == timeout);
_timeout = _ignoreTimeout
? (Int32)Regex.InfiniteMatchTimeout.TotalMilliseconds
: (Int32)(timeout.TotalMilliseconds + 0.5); // Round
_runregex = regex;
_runtext = text;
_runtextbeg = textbeg;
_runtextend = textend;
_runtextstart = textstart;
bump = _runregex.RightToLeft ? -1 : 1;
stoppos = _runregex.RightToLeft ? _runtextbeg : _runtextend;
_runtextpos = textstart;
// If previous match was empty or failed, advance by one before matching
if (prevlen == 0)
{
if (_runtextpos == stoppos)
{
return(Match.Empty);
}
_runtextpos += bump;
}
StartTimeoutWatch();
for (; ;)
{
#if DBG
if (_runregex.Debug)
{
Debug.WriteLine("");
Debug.WriteLine("Search range: from " + _runtextbeg.ToString(CultureInfo.InvariantCulture) + " to " + _runtextend.ToString(CultureInfo.InvariantCulture));
Debug.WriteLine("Firstchar search starting at " + _runtextpos.ToString(CultureInfo.InvariantCulture) + " stopping at " + stoppos.ToString(CultureInfo.InvariantCulture));
}
#endif
if (FindFirstChar())
{
CheckTimeout();
if (!initted)
{
InitMatch();
initted = true;
}
#if DBG
if (_runregex.Debug)
{
Debug.WriteLine("Executing engine starting at " + _runtextpos.ToString(CultureInfo.InvariantCulture));
Debug.WriteLine("");
}
#endif
Go();
if (_runmatch._matchcount[0] > 0)
{
// We'll return a match even if it touches a previous empty match
return(TidyMatch(quick));
}
// reset state for another go
_runtrackpos = _runtrack.Length;
_runstackpos = _runstack.Length;
_runcrawlpos = _runcrawl.Length;
}
// failure!
if (_runtextpos == stoppos)
{
TidyMatch(true);
return(Match.Empty);
}
// Recognize leading []* and various anchors, and bump on failure accordingly
// Bump by one and start again
_runtextpos += bump;
}
// We never get here
}