internal void RegexRunnerFinished(RegexRunner sender) { Busy = false; Runner = null; if (sender.Error != null) { Status.Text = "Error encountered during processing"; MessageBox.Show(this, sender.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // replace may be with nothing (zero length string), so find mode is when replace is null if (sender.Replace == null) // find { Captures.BeginUpdate(); int i = 0; foreach (Match m in sender.Matches) { i++; TreeNode n = Captures.Nodes.Add("{" + ReplaceNewLines(m.Value) + "}"); foreach (Group g in m.Groups) { if (g.Captures.Count > 1) { TreeNode nn = n.Nodes.Add("..."); foreach (Capture c in g.Captures) { nn.Nodes.Add("{" + ReplaceNewLines(c.Value) + "}"); } } else if (g.Captures.Count == 1) { n.Nodes.Add(ReplaceNewLines("{" + g.Captures[0].Value) + "}"); } } // For performance limit tree view to first 500 results if (i > 499) { break; } } switch (sender.Matches.Count) { case 0: Status.Text = "No matches"; break; case 1: Status.Text = "1 match found"; break; default: if (sender.Matches.Count > 500) { Status.Text = sender.Matches.Count + " matches found (showing first 500)"; } else { Status.Text = sender.Matches.Count + " matches found"; } break; } Status.Text += " in " + sender.GetExecutionTime() + " ms"; Captures.ExpandAll(); Captures.EndUpdate(); } else // replace { ResultText.Text = sender.Result; if (sender.Matches.Count != 1) { Status.Text = sender.Matches.Count + " replacements performed"; } else { Status.Text = "1 replacement performed"; } Status.Text += " in " + sender.GetExecutionTime() + " ms"; Captures.Visible = false; ResultText.Visible = true; txtInput.Text = NewLineRegex.Replace(txtInput.Text, "\r\n"); // make user-inserted \n show as a genuine newline ResultText.Text = ResultText.Text.Replace("\\n", "\r\n"); // make any existing newlines in replace text display as newlines ResultText.Text = NewLineRegex.Replace(ResultText.Text, "\r\n"); } }
internal void RegexRunnerFinished(RegexRunner sender) { Busy = false; Runner = null; if (sender.Error != null) { Status.Text = "Error encountered during processing"; MessageBox.Show(this, sender.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(sender.Replace)) // find { Captures.BeginUpdate(); foreach (Match m in sender.Matches) { TreeNode n = Captures.Nodes.Add("{" + ReplaceNewLines(m.Value) + "}"); foreach (Group g in m.Groups) { if (g.Captures.Count > 1) { TreeNode nn = n.Nodes.Add("..."); foreach (Capture c in g.Captures) { nn.Nodes.Add("{" + ReplaceNewLines(c.Value) + "}"); } } else if (g.Captures.Count == 1) { n.Nodes.Add(ReplaceNewLines("{" + g.Captures[0].Value) + "}"); } } } switch (sender.Matches.Count) { case 0: Status.Text = "No matches"; break; case 1: Status.Text = "1 match found"; break; default: Status.Text = sender.Matches.Count + " matches found"; break; } Status.Text += " in " + sender.GetExecutionTime() + " ms"; Captures.ExpandAll(); Captures.EndUpdate(); } else // replace { ResultText.Text = sender.Result; if (sender.Matches.Count != 1) { Status.Text = sender.Matches.Count + " replacements performed"; } else { Status.Text = "1 replacement performed"; } Status.Text += " in " + sender.GetExecutionTime() + " ms"; Captures.Visible = false; ResultText.Visible = true; txtInput.Text = NewLineRegex.Replace(txtInput.Text, "\r\n"); ResultText.Text = ResultText.Text.Replace("\r\n", "\n"); ResultText.Text = NewLineRegex.Replace(ResultText.Text, "\r\n"); } }