private void UpdateFind_WorkerThread(object parameters)
{
string text = (string) ((object[])parameters)[0];
string findText = (string) ((object[])parameters)[1];
bool highLightFirstMatch = (bool)((object[])parameters)[2];
bool matchCase = (bool)((object[])parameters)[3];
bool useRegEx = (bool)((object[])parameters)[4];
string replacementText = (string)((object[])parameters)[5];
TextEditor textEditor = (TextEditor)((object[])parameters)[6];
int findIndex = 0;
int matchLength = 0;
int count = 0;
System.Text.RegularExpressions.Regex regEx = null;
if (useRegEx)
{
try
{
regEx = new System.Text.RegularExpressions.Regex(findText, matchCase ? System.Text.RegularExpressions.RegexOptions.None : System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
catch
{
return;
}
}
while (true)
{
if (useRegEx)
{
try
{
System.Text.RegularExpressions.Match regExMatch = regEx.Match(text, findIndex);
if (regExMatch.Success)
{
findIndex = regExMatch.Index;
matchLength = regExMatch.Length;
}
else
{
findIndex = -1;
matchLength = 0;
}
}
catch
{
findIndex = -1;
matchLength = 0;
}
}
else
{
findIndex = text.IndexOf(findText, findIndex, matchCase ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);
matchLength = findText.Length;
}
if (findIndex >= 0)
{
count++;
if (count == 1 && highLightFirstMatch == true)
{
Object[] callingParameters = new Object[3];
callingParameters[0] = findIndex;
callingParameters[1] = matchLength;
callingParameters[2] = true;
this.Dispatcher.BeginInvoke(new EditorFindOnPageSelection_Delegate(textEditor.Select), callingParameters);
}
if (count % 10 == 0)
{
this.Dispatcher.BeginInvoke(new SetStatusText_Delegate(this.SetStatusText), count.ToString() + " MATCHES");
}
if (replacementText != null)
{
textEditor.ReplaceText(findIndex, matchLength, replacementText);
}
findIndex++;
if (findIndex >= text.Length)
{
break;
}
}
else
{
break;
}
}
if (count == 0)
{
this.Dispatcher.BeginInvoke(new SetStatusText_Delegate(this.SetStatusText), "NO MATCHES FOUND");
Object[] callingParameters = new Object[3];
callingParameters[0] = 0;
callingParameters[1] = 0;
callingParameters[2] = true;
this.Dispatcher.BeginInvoke(new EditorFindOnPageSelection_Delegate(textEditor.Select), callingParameters);
}
else
{
this.Dispatcher.BeginInvoke(new SetStatusText_Delegate(this.SetStatusText), count.ToString() + " MATCHES");
}
}