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


C# CharSetSolver.MkBddForIntRanges方法代码示例

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


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

示例1: WriteRangeFields

        private static void WriteRangeFields(BitWidth encoding, StreamWriter sw, string field)
        {
            int bits = (int)encoding;
            int maxChar = (1 << bits) - 1;
            var catMap = new Dictionary<UnicodeCategory, Ranges>();
            for (int c = 0; c < 30; c++)
                catMap[(UnicodeCategory)c] = new Ranges();
            Ranges whitespace = new Ranges();
            Ranges wordcharacter = new Ranges();
            for (int i = 0; i <= maxChar; i++)
            {
                char ch = (char)i;
                if (char.IsWhiteSpace(ch))
                    whitespace.Add(i);
                UnicodeCategory cat = char.GetUnicodeCategory(ch);
                catMap[cat].Add(i);
                int catCode = (int)cat;
                //in .NET 3.5
                if (bits == 7)
                    if (catCode == 0 || catCode == 1 || catCode == 2 || catCode == 3 || catCode == 4 || catCode == 5 || catCode == 8 || catCode == 18)
                        wordcharacter.Add(i);
            }
            //generate bdd reprs for each of the category ranges
            BDD[] catBDDs = new BDD[30];
            CharSetSolver bddb = new CharSetSolver(encoding);
            for (int c = 0; c < 30; c++)
                catBDDs[c] = bddb.MkBddForIntRanges(catMap[(UnicodeCategory)c].ranges);

            BDD whitespaceBdd = bddb.MkBddForIntRanges(whitespace.ranges);

            //in .NET 3.5 category 5 was NOT a word character
            //union of categories 0,1,2,3,4,8,18
            BDD wordCharBdd = bddb.MkOr(catBDDs[0],
                              bddb.MkOr(catBDDs[1],
                              bddb.MkOr(catBDDs[2],
                              bddb.MkOr(catBDDs[3],
                              bddb.MkOr(catBDDs[4],
                              bddb.MkOr(catBDDs[5],
                              bddb.MkOr(catBDDs[8], catBDDs[18])))))));
            if (bits == 7)
            {
                sw.WriteLine(@"/// <summary>
            /// Array of 30 UnicodeCategory ranges. Each entry is a pair of integers.
            /// corresponding to the lower and upper bounds of the unicodes of the characters
            /// that have the given UnicodeCategory code (between 0 and 29).
            /// </summary>");
                sw.WriteLine("public static int[][][] " + field + " = new int[][][]{");
                foreach (UnicodeCategory c in catMap.Keys)
                {
                    sw.WriteLine("//{0}({1}):", c, (int)c);
                    if (catMap[c].Count == 0)
                        sw.WriteLine("null,");
                    else
                    {
                        sw.WriteLine("new int[][]{");
                        foreach (int[] range in catMap[c].ranges)
                            sw.WriteLine("    new int[]{" + string.Format("{0},{1}", range[0], range[1]) + "},");
                        sw.WriteLine("},");
                    }
                }
                sw.WriteLine("};");
            }

            sw.WriteLine(@"/// <summary>
            /// Compact BDD encodings of the categories.
            /// </summary>");
            sw.WriteLine("public static int[][] " + field + "Bdd = new int[][]{");
            foreach (UnicodeCategory c in catMap.Keys)
            {
                sw.WriteLine("//{0}({1}):", c, (int)c);
                BDD catBdd = catBDDs[(int)c];
                if (catBdd == null || catBdd.IsEmpty)
                    sw.WriteLine("null, //false");
                else if (catBdd.IsFull)
                    sw.WriteLine("new int[]{0,0}, //true");
                else
                {
                    sw.WriteLine("new int[]{");
                    foreach (var arc in bddb.SerializeCompact(catBdd))
                        sw.WriteLine("{0},", arc);
                    sw.WriteLine("},");
                }
            }
            sw.WriteLine("};");

            if (bits == 7)
            {
                sw.WriteLine(@"/// <summary>
            /// Whitespace character ranges.
            /// </summary>");
                sw.WriteLine("public static int[][] " + field + "Whitespace = new int[][]{");
                foreach (int[] range in whitespace.ranges)
                    sw.WriteLine("    new int[]{" + string.Format("{0},{1}", range[0], range[1]) + "},");
                sw.WriteLine("};");

                sw.WriteLine(@"/// <summary>
            /// Word character ranges.
            /// </summary>");
                sw.WriteLine("public static int[][] " + field + "WordCharacter = new int[][]{");
                foreach (int[] range in wordcharacter.ranges)
//.........这里部分代码省略.........
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:101,代码来源:UnicodeCategoryRangesGenerator.cs


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