当前位置: 首页>>代码示例>>C#>>正文


C# CharSetSolver.ConvertToRegex方法代码示例

本文整理汇总了C#中CharSetSolver.ConvertToRegex方法的典型用法代码示例。如果您正苦于以下问题:C# CharSetSolver.ConvertToRegex方法的具体用法?C# CharSetSolver.ConvertToRegex怎么用?C# CharSetSolver.ConvertToRegex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CharSetSolver的用法示例。


在下文中一共展示了CharSetSolver.ConvertToRegex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestRegex

        static void TestRegex(Regex regex)
        {
            var solver = new CharSetSolver();
            string myregex = regex.ToString();

            //Regex.CompileToAssembly(new RegexCompilationInfo[] { new RegexCompilationInfo(myregex, RegexOptions.None, "EvilRegex", "RegexTransfomer", true) },
            //    new System.Reflection.AssemblyName("EvilRegex"));

            var sfa = solver.Convert(myregex, regex.Options).RemoveEpsilons();
            var sfaDet = sfa.Determinize();
            var sfaMin = sfaDet.Minimize();

            //solver.ShowGraph(sfa, "sfa");
            //solver.ShowGraph(sfaDet, "sfaDet");
            //solver.ShowGraph(sfaMin, "sfaMin");

            var cs = solver.ToCS(sfaMin, true, "MyRegex", "RegexTransfomer");

            var regexMin = solver.ConvertToRegex(sfaMin);

            Console.WriteLine("------- given regex --------");
            Console.WriteLine(myregex);
            Console.WriteLine("----------------------------");

            Console.WriteLine("-------- regexMin ----------");
            Console.WriteLine(regexMin);
            Console.WriteLine("----------------------------");

            Console.WriteLine("-------- cs ----------------");
            Console.WriteLine(cs.SourceCode);
            Console.WriteLine("----------------------------");

            string sIn = solver.GenerateMember(sfaMin);
            string sOut = solver.GenerateMember(sfaMin.Complement());
            string s = sIn;
            int t1;
            int t2;
            int t3;
            for (int i = 0; i < 2; i++)
            {
                //original regex
                t1 = System.Environment.TickCount;
                bool res1 = false;
                for (int j = 0; j < 100000; j++)
                    res1 = Regex.IsMatch(s, regex.ToString(), regex.Options);
                //res1 = evilregex.IsMatch(s);
                t1 = System.Environment.TickCount - t1;

                ////minimized regex
                //t2 = System.Environment.TickCount;
                //bool res2 = false;
                //for (int j = 0; j < 100000; j++)
                //    res2 = Regex.IsMatch(s, regexMin, regex.Options);
                //t2 = System.Environment.TickCount - t2;

                //code from minimized regex
                t3 = System.Environment.TickCount;
                bool res3 = false;
                for (int j = 0; j < 100000; j++)
                    res3 = cs.IsMatch(s);
                t3 = System.Environment.TickCount - t3;
                Console.WriteLine(String.Format("{0}ms({1}), {2}ms({3})", t1, res1, t3, res3));
                s = sOut;
            }
            Console.WriteLine("done...(press any key)");
            Console.ReadKey();
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:67,代码来源:CodeGenTests.cs


注:本文中的CharSetSolver.ConvertToRegex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。