Beispiel #1
0
        static ResultsViewModel()
        {
            //SampleGrid = new InputFragments(
            //  new InputFragment(null, String.Empty),
            //  new InputFragment(0, "Chunk #1"),
            //  new InputFragment(1, "Chunk #2"),
            //  new InputFragment(2, "Chunk #3"),
            //  new InputFragment(3, "Chunk #4"),
            //  new InputFragment(4, "Chunk #5"),
            //  new InputFragment(5, "Chunk #6"),
            //  new InputFragment(6, "Chunk #7"));
            SampleGrid = new LineFragments(
                new LineFragment(new Line("Line # 1 of text", 0, 10), 0, null, String.Empty),
                new LineFragment(new Line("Line # 1 of text", 0, 10), 0, null, String.Empty),
                new LineFragment(new Line("Line # 1 of text", 0, 10), 0, null, String.Empty),
                new LineFragment(new Line("Line # 2 of text", 0, 10), 1, 0, "Chunk #1"),
                new LineFragment(new Line("Line # 2 of text", 0, 10), 1, 1, "Chunk #2"),
                new LineFragment(new Line("Line # 2 of text", 0, 10), 1, 2, "Chunk #3"),
                new LineFragment(new Line("Line # 6 of text", 0, 10), 2, 0, "Replacement #6"),
                new LineFragment(new Line("Line # 7 of text", 0, 10), 3, 0, "Replacement #7"));
            // SampleGrid = new LineReplacements(
            //   new LineReplacement(new Line("Line # 1 of text", 0, 10), 0, "Replacement #1"),
            //   new LineReplacement(new Line("Line # 2 of text", 0, 10), 1, "Replacement #2"),
            //   new LineReplacement(new Line("Line # 3 of text", 0, 10), 2, "Replacement #3"),
            //   new LineReplacement(new Line("Line # 4 of text", 0, 10), 3, "Replacement #4"),
            //   new LineReplacement(new Line("Line # 5 of text", 0, 10), 4, "Replacement #5"),
            //   new LineReplacement(new Line("Line # 6 of text", 0, 10), 5, "Replacement #6"),
            //   new LineReplacement(new Line("Line # 7 of text", 0, 10), 6, "Replacement #7"));

            SampleText =
                "Line # 1 of text\r\n" +
                "Line # 2 of text\r\n" +
                "Line # 3 of text\r\n" +
                "Line # 4 of text\r\n" +
                "Line # 5 of text\r\n" +
                "Line # 6 of text\r\n";

            SampleTree = LineNode.GetSamples().ToArray();
        }
        static void ExecuteMatch(IOptions snapshot, ResultsViewModel results)
        {
            var regex        = snapshot.CreateRegex(1000);
            var groupNames   = regex.GetGroupNames();
            var groupNumbers = regex.GetGroupNumbers();

            #region build tree
            if (snapshot.MultilineInput)
            {
                var checker = new Checker(SanityLimit, 5000);
                var nodes   = new List <LineNode>();
                var lines   = Line.Split(snapshot.InputText);

                for (var i = 0; i < lines.Length; i++)
                {
                    if (checker.Terminated)
                    {
                        break;
                    }

                    var line     = lines[i];
                    var lineNode = new LineNode(line, i);
                    nodes.Add(lineNode);

                    checker.Adjust();

                    var match = regex.Match(snapshot.InputText, line.Index, line.Length);

                    if (match.Success)
                    {
                        for (var j = 0; match.Success; j++, match = match.NextMatch())
                        {
                            if (checker.Terminated)
                            {
                                break;
                            }

                            var matchNode = new MatchNode(match, j);
                            ((IList <MatchNode>)lineNode.Matches).Add(matchNode);

                            checker.Adjust();

                            for (var k = 0; k < groupNames.Length; k++)
                            {
                                if (checker.Terminated)
                                {
                                    break;
                                }

                                var number = groupNumbers[k];
                                var name   = groupNames[k];
                                var group  = match.Groups[number];

                                var groupNode = new GroupNode(group, k, number, name);
                                ((IList <GroupNode>)matchNode.Groups).Add(groupNode);

                                checker.Adjust();

                                for (var l = 0; l < group.Captures.Count; l++)
                                {
                                    if (checker.Terminated)
                                    {
                                        break;
                                    }

                                    var capture     = group.Captures[l];
                                    var captureNode = new CaptureNode(capture, l);
                                    ((IList <CaptureNode>)groupNode.Captures).Add(captureNode);

                                    checker.Adjust();
                                }
                            }
                        }
                    }
                    else
                    {
                        var matchNode = new MatchNode(match, 0);
                        ((IList <MatchNode>)lineNode.Matches).Add(matchNode);

                        checker.Adjust();
                    }
                }

                results.SetTree(nodes, checker.State);
            }
            else
            {
                var checker = new Checker(SanityLimit, 5000);
                var nodes   = new List <MatchNode>();
                var match   = regex.Match(snapshot.InputText);

                if (match.Success)
                {
                    for (var j = 0; match.Success; j++, match = match.NextMatch())
                    {
                        if (checker.Terminated)
                        {
                            break;
                        }

                        var matchNode = new MatchNode(match, j);
                        nodes.Add(matchNode);

                        checker.Adjust();

                        for (var k = 0; k < groupNames.Length; k++)
                        {
                            if (checker.Terminated)
                            {
                                break;
                            }

                            var number = groupNumbers[k];
                            var name   = groupNames[k];
                            var group  = match.Groups[number];

                            var groupNode = new GroupNode(group, k, number, name);
                            ((IList <GroupNode>)matchNode.Groups).Add(groupNode);

                            checker.Adjust();

                            for (var l = 0; l < group.Captures.Count; l++)
                            {
                                if (checker.Terminated)
                                {
                                    break;
                                }

                                var capture     = group.Captures[l];
                                var captureNode = new CaptureNode(capture, l);
                                ((IList <CaptureNode>)groupNode.Captures).Add(captureNode);

                                checker.Adjust();
                            }
                        }
                    }
                }
                else
                {
                    var matchNode = new MatchNode(match, 0);
                    nodes.Add(matchNode);

                    checker.Adjust();
                }

                results.SetTree(nodes, checker.State);
            }
            #endregion
        }