コード例 #1
0
        static void ExecuteReplace(IOptions snapshot, ResultsViewModel results)
        {
            var regex = snapshot.CreateRegex(1000);

            if (snapshot.MultilineInput)
            {
                var checker = new Checker(SanityLimit, 5000);
                var lines   = Line.Split(snapshot.InputText);
                var list    = new List <LineReplacement>();

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

                    var line   = lines[i];
                    var result = regex.Replace(line.Value, snapshot.ReplacementText);
                    list.Add(new LineReplacement(line, i + 1, result));

                    checker.Adjust();
                }

                results.SetGrid(new LineReplacements(list.ToArray()), checker.State);
            }
            else
            {
                var input  = snapshot.InputText;
                var result = regex.Replace(input, snapshot.ReplacementText);

                results.SetText(result);
            }
        }
コード例 #2
0
        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
        }
コード例 #3
0
        static void ExecuteSplit(IOptions snapshot, ResultsViewModel results)
        {
            var regex = snapshot.CreateRegex(1000);

            if (snapshot.MultilineInput)
            {
                var checker = new Checker(SanityLimit, 5000);
                var lines   = Line.Split(snapshot.InputText);
                var list    = new List <LineFragment>();
                for (var i = 0; i < lines.Length; i++)
                {
                    if (checker.Terminated)
                    {
                        break;
                    }

                    var line   = lines[i];
                    var result = regex.Split(line.Value);
                    checker.Adjust();

                    if (result.Length == 0)
                    {
                        list.Add(new LineFragment(line, i + 1, null, String.Empty));

                        checker.Adjust();
                    }
                    else
                    {
                        for (var j = 0; j < result.Length; j++)
                        {
                            if (checker.Terminated)
                            {
                                break;
                            }

                            list.Add(new LineFragment(line, i + 1, j, result[j]));

                            checker.Adjust();
                        }
                    }
                }

                results.SetGrid(new LineFragments(list.ToArray()), checker.State);
            }
            else
            {
                var checker = new Checker(SanityLimit, 5000);
                var list    = new List <InputFragment>();
                var input   = snapshot.InputText;
                var result  = regex.Split(input);
                if (result.Length == 0)
                {
                    list.Add(new InputFragment(null, String.Empty));

                    checker.Adjust();
                }
                else
                {
                    for (var j = 0; j < result.Length; j++)
                    {
                        if (checker.Terminated)
                        {
                            break;
                        }

                        list.Add(new InputFragment(j, result[j]));

                        checker.Adjust();
                    }
                }

                results.SetGrid(new InputFragments(list.ToArray()), checker.State);
            }
        }