private void AbortProcessing() { Busy = false; if (Runner == null) { return; } Runner.Abort(); Runner = null; Status.Text = "Processing aborted"; }
private void Replace_Click(object sender, EventArgs e) { try { Captures.Nodes.Clear(); ResultText.Text = ""; Status.Text = ""; txtInput.Text = txtInput.Text.Replace("\r\n", "\n"); Busy = true; Regex r = new Regex(txtFind.Text, Options); Runner = new RegexRunner(this, txtInput.Text, txtReplace.Text.Replace("\\n", "\r\n"), r); } catch (Exception ex) { ErrorHandler(ex); Busy = false; } }
private void FindBtn_Click(object sender, EventArgs e) { try { Captures.Nodes.Clear(); Captures.Visible = true; ResultText.Text = ""; ResultText.Visible = false; Status.Text = ""; Busy = true; Regex r = new Regex(txtFind.Text, Options); Runner = new RegexRunner(this, txtInput.Text, r); } catch (Exception ex) { ErrorHandler(ex); Busy = false; } }
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 { foreach (Match m in sender.Matches) { TreeNode n = Captures.Nodes.Add("{" + ReplaceNewLines(m.Value) + "}"); foreach (Group g in m.Groups) { // TODO: Is there any way to get the name of the group when explicit capture is on? 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) + "}"); } } } if (sender.Matches.Count == 0) { Status.Text = "No matches"; } else if (sender.Matches.Count == 1) { Status.Text = "1 match found"; } else { Status.Text = sender.Matches.Count + " matches found"; } Captures.ExpandAll(); } else // replace { ResultText.Text = sender.Result; if (sender.Matches.Count != 1) { Status.Text = sender.Matches.Count + " replacements performed"; } else { Status.Text = "1 replacement performed"; } Captures.Visible = false; ResultText.Visible = true; txtInput.Text = txtInput.Text.Replace("\n", "\r\n"); ResultText.Text = ResultText.Text.Replace("\r\n", "\n"); ResultText.Text = ResultText.Text.Replace("\n", "\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; } // 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 { 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(); } 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"); } }