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


C# CharSetSolver.MkCharSetFromRange方法代码示例

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


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

示例1: ComputeIgnoreCaseDistionary

        private static Dictionary<char, BDD> ComputeIgnoreCaseDistionary(CharSetSolver solver)
        {
            var ignoreCase = new Dictionary<char, BDD>();
            for (uint i = 0; i <= 0xFFFF; i++)
            {
                char c = (char)i;
                char cU = char.ToUpper(c); // (char.IsLetter(char.ToUpper(c)) ? char.ToUpper(c) : c);
                char cL = char.ToLower(c); // (char.IsLetter(char.ToLower(c)) ? char.ToLower(c) : c);
                if (c != cU || c != cL || cU != cL)
                {
                    //make sure that the regex engine considers c as being equivalent to cU and cL, else ignore c
                    //in some cases c != cU but the regex engine does not consider the chacarters equivalent wrt the ignore-case option.
                    //These characters are:
                    //c=\xB5,cU=\u039C
                    //c=\u0131,cU=I
                    //c=\u017F,cU=S
                    //c=\u0345,cU=\u0399
                    //c=\u03C2,cU=\u03A3
                    //c=\u03D0,cU=\u0392
                    //c=\u03D1,cU=\u0398
                    //c=\u03D5,cU=\u03A6
                    //c=\u03D6,cU=\u03A0
                    //c=\u03F0,cU=\u039A
                    //c=\u03F1,cU=\u03A1
                    //c=\u03F5,cU=\u0395
                    //c=\u1E9B,cU=\u1E60
                    //c=\u1FBE,cU=\u0399
                    if (System.Text.RegularExpressions.Regex.IsMatch(cU.ToString() + cL.ToString(), "^(?i:" + StringUtility.Escape(c) + ")+$"))
                    {
                        BDD equiv = solver.False;

                        if (ignoreCase.ContainsKey(c))
                            equiv = equiv.Or(ignoreCase[c]);
                        if (ignoreCase.ContainsKey(cU))
                            equiv = equiv.Or(ignoreCase[cU]);
                        if (ignoreCase.ContainsKey(cL))
                            equiv = equiv.Or(ignoreCase[cL]);

                        equiv = equiv.Or(solver.MkCharSetFromRange(c, c)).Or(solver.MkCharSetFromRange(cU, cU)).Or(solver.MkCharSetFromRange(cL, cL));

                        foreach (char d in solver.GenerateAllCharacters(equiv))
                            ignoreCase[d] = equiv;
                    }
                    //else
                    //{
                    //    outp += "c=" + StringUtility.Escape(c) + "," + "cU=" + StringUtility.Escape(cU);
                    //    Console.WriteLine("c=" + StringUtility.Escape(c) + "," + "cL=" + StringUtility.Escape(cL) + "," + "cU=" + StringUtility.Escape(cU));
                    //}
                }
            }
            return ignoreCase;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:52,代码来源:IgnoreCaseRelationGenerator.cs

示例2: ReadFromString

        public static Automaton<BDD> ReadFromString(CharSetSolver solver, string automaton)
        {
            var lines = automaton.Split(new char[] { '\n','\r' }, StringSplitOptions.RemoveEmptyEntries);
            int initialState = int.Parse(lines[0]);
            var moves = new Dictionary<Pair<int, int>, BDD>();
            var allmoves = new List<Move<BDD>>();
            int[] finals = Array.ConvertAll(lines[1].TrimEnd(' ').Split(' '), s => int.Parse(s));
            for (int i = 2; i < lines.Length; i++)
            {
                int[] elems = Array.ConvertAll(lines[i].TrimEnd(' ').Split(' '), s => int.Parse(s));
                var key = new Pair<int, int>(elems[0], elems[3]);
                if (elems[1] == -1)
                    allmoves.Add(Move<BDD>.Epsilon(elems[0], elems[3]));
                else
                {
                    var pred = solver.MkCharSetFromRange((char)elems[1], (char)elems[2]);
                    if (moves.ContainsKey(key))
                        moves[key] = solver.MkOr(moves[key], pred);
                    else
                        moves[key] = pred;
                }
            }
            foreach (var kv in moves)
                allmoves.Add(Move<BDD>.Create(kv.Key.First, kv.Key.Second, kv.Value));

            var aut = Automaton<BDD>.Create(solver, initialState, finals, allmoves);
            return aut;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:28,代码来源:RegexToRangeAutomatonSerializer.cs

示例3: ReadFromRanges

        /// <summary>
        /// Each transition has the form int[]{fromState, intervalStart, intervalEnd, toState}.
        /// If intervalStart = intervalEnd = -1 then this is an epsilon move.
        /// </summary>
        public static Automaton<BDD> ReadFromRanges(CharSetSolver solver, int initialState, int[] finalStates, IEnumerable<int[]> transitions)
        {
            var moves = new Dictionary<Pair<int, int>, BDD>();
            var allmoves = new List<Move<BDD>>();
            int[] finals = finalStates;
            foreach (var elems in transitions)
            {
                var key = new Pair<int, int>(elems[0], elems[3]);
                if (elems[1] == -1)
                    allmoves.Add(Move<BDD>.Epsilon(elems[0], elems[3]));
                else
                {
                    var pred = solver.MkCharSetFromRange((char)elems[1], (char)elems[2]);
                    if (moves.ContainsKey(key))
                        moves[key] = solver.MkOr(moves[key], pred);
                    else
                        moves[key] = pred;
                }
            }
            foreach (var kv in moves)
                allmoves.Add(Move<BDD>.Create(kv.Key.First, kv.Key.Second, kv.Value));

            var aut = Automaton<BDD>.Create(solver, initialState, finals, allmoves);
            return aut;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:29,代码来源:RegexToRangeAutomatonSerializer.cs

示例4: CSharpGenerator

 public CSharpGenerator(Automaton<BDD> automaton, CharSetSolver solver, string classname, string namespacename, bool OptimzeForAsciiInput = true)
 {
     this.solver = solver;
     this.automaton = automaton;
     this.namespacename = namespacename;
     this.classname = classname;
     ASCII = solver.MkCharSetFromRange('\0', '\x7F');
     helper_predicates = new HelperPredicates(solver, OptimzeForAsciiInput);
 }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:9,代码来源:CSharpStringMatcher.cs

示例5: TestRanges

 public void TestRanges()
 {
     CharSetSolver solver = new CharSetSolver(BitWidth.BV16);
     BDD cond = solver.MkCharSetFromRange('A', 'Y');
     Pair<uint, uint>[] ranges = solver.ToRanges(cond);
     Assert.AreEqual<int>(1, ranges.Length);
     Assert.AreEqual<uint>((uint)'A', ranges[0].First);
     Assert.AreEqual<uint>((uint)'Y', ranges[0].Second);
 }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:9,代码来源:CharSetTests.cs

示例6: TestDotGen

 public void TestDotGen()
 {
     CharSetSolver solver = new CharSetSolver(BitWidth.BV7);
     BDD cond = solver.MkCharSetFromRange('\0', '\x0F');
     int cnt = (int)solver.ComputeDomainSize(cond);
     cond.ToDot(@"bdd2.dot");
 }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:7,代码来源:CharSetTests.cs

示例7: CreateUlongArray

        private static void CreateUlongArray(StreamWriter sw)
        {
            sw.WriteLine("/// <summary>");
            sw.WriteLine("/// Serialized BDD for mapping characters to their case-ignoring equivalence classes.");
            sw.WriteLine("/// </summary>");
            sw.WriteLine("public static ulong[] ignorecase = new ulong[]{");
            CharSetSolver solver = new CharSetSolver();

            Dictionary<char, BDD> ignoreCase = ComputeIgnoreCaseDistionary(solver);

            BDD ignorecase = solver.False;
            foreach (var kv in ignoreCase)
            {
                var a = solver.MkCharSetFromRange(kv.Key, kv.Key);
                var b = kv.Value;
                ignorecase = ignorecase.Or(a.ShiftLeft(16).And(b));
            }
            var ignorecaseArray = solver.Serialize(ignorecase);
            for (int i = 0; i < ignorecaseArray.Length; i++)
                sw.WriteLine("0x{0:X16},", ignorecaseArray[i]);

            sw.WriteLine("};"); //end of array
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:23,代码来源:IgnoreCaseRelationGenerator.cs


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