Exemplo n.º 1
0
        public static void LoadRegexJob(String path)
        {
            TaskWindow taskWindow = new TaskWindow
                                    (
                delegate(Object argument)
            {
                return(RegexHelper.Match(AppState.Current.Input));
            },
                path
                                    )
            {
                Owner = App.MainWindow
            };

            taskWindow.ShowDialog();

            if (taskWindow.Exception == null)
            {
                RegexInput regexInput = taskWindow.Result as RegexInput;

                if (regexInput != null)
                {
                    AppState.Current.Input = regexInput;
                    AppState.Current.Update(path);
                }
            }
            else
            {
                ExceptionMessageBox.Show(App.MainWindow, App.Metadata.AssemblyTitle,
                                         "Invalid job file format.", taskWindow.Exception.InnerException);
            }
        }
Exemplo n.º 2
0
        public static Int64 Measure(RegexInput input)
        {
            Regex     regex     = new Regex(input.RegexPattern, input.Options, App.Settings.Main.RegexOperationTimeout);
            Stopwatch stopWatch = new Stopwatch();

            try
            {
                stopWatch.Start();
                regex.IsMatch(input.Text);
            }
            finally
            {
                stopWatch.Stop();
            }

            return(stopWatch.ElapsedTicks);
        }
Exemplo n.º 3
0
        public static RegexInput LoadRegexInput(String path)
        {
            RegexInput input = new RegexInput();

            using (XmlReader reader = XmlReader.Create(path))
            {
                reader.ReadToFollowing("Input");

                reader.Read(); // First child node for input data

                input.RegexPattern   = reader.ReadElementContentAsString();
                input.ReplacePattern = reader.ReadElementContentAsString();
                input.Text           = reader.ReadElementContentAsString();
                input.Options        = (RegexOptions)Enum.Parse(typeof(RegexOptions), reader.ReadElementContentAsString());
            }

            return(input);
        }
Exemplo n.º 4
0
        public static RegexResult Match(RegexInput input)
        {
            Regex           regex           = new Regex(input.RegexPattern, input.Options, App.Settings.Main.RegexOperationTimeout);
            Stopwatch       stopWatch       = new Stopwatch();
            MatchCollection matchCollection = null;

            try
            {
                stopWatch.Start();
                matchCollection = regex.Matches(input.Text);
            }
            finally
            {
                stopWatch.Stop();
            }

            RegexResult regexResult = new RegexResult();

            foreach (Match match in matchCollection)
            {
                RegexMatch regexMatch = new RegexMatch(match.Value, match.Index);

                foreach (Group group in match.Groups)
                {
                    RegexMatch groupMatch = new RegexMatch(group.Value, group.Index);

                    foreach (Capture capture in group.Captures)
                    {
                        RegexMatch captureMatch = new RegexMatch(capture.Value, capture.Index);

                        groupMatch.Children.Add(captureMatch);
                    }

                    regexMatch.Children.Add(groupMatch);
                }

                regexResult.Results.Add(regexMatch);
            }

            regexResult.Update(stopWatch.ElapsedTicks);

            return(regexResult);
        }
Exemplo n.º 5
0
        public static void SaveRegexInput(String path, RegexInput input)
        {
            using (XmlWriter writer = XmlWriter.Create(path))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement(App.Metadata.AssemblyInternalName, FileHelper.Namespace);

                writer.WriteStartElement("Input");

                writer.WriteElementString("RegexPattern", input.RegexPattern);
                writer.WriteElementString("ReplacePattern", input.ReplacePattern);
                writer.WriteElementString("Text", input.Text);
                writer.WriteElementString("Options", input.Options.ToString());

                writer.WriteEndElement(); // </Input>

                writer.WriteEndElement(); // </RegexTester>
                writer.WriteEndDocument();
            }
        }
Exemplo n.º 6
0
        public static String Replace(RegexInput input)
        {
            Regex regex = new Regex(input.RegexPattern, input.Options, App.Settings.Main.RegexOperationTimeout);

            return(regex.Replace(input.Text, input.ReplacePattern));
        }
Exemplo n.º 7
0
        public static String[] Split(RegexInput input)
        {
            Regex regex = new Regex(input.RegexPattern, input.Options, App.Settings.Main.RegexOperationTimeout);

            return(regex.Split(input.Text));
        }
Exemplo n.º 8
0
 private void RegexMenuItem_Click(object sender, RoutedEventArgs e)
 {
     RegexInput inputWindow = new RegexInput();
     inputWindow.Owner = this;
     inputWindow.ShowDialog();
     regexString = inputWindow.RegexString;
     if(regexString != string.Empty)
     {
         RegexContent.Text = regexString;
         var parser = new RegexParser.Parser(regexString);
         var exp = parser.ParseExpression();
         EpsilonNfa = exp.GenerateExpsilonNfa();
         Nfa = Automaton.RemoveEpsilon(EpsilonNfa);
         MultiValueDictionary<State, State> statesMap;
         Dfa = Automaton.NfaToDfa(Nfa, out statesMap);
     }
 }