示例#1
0
        private static StrongBidiCategory GetBidiCategoryNoBoundsChecks(uint codePoint)
        {
            nuint offset = GetCategoryCasingTableOffsetNoBoundsChecks(codePoint);

            // Each entry of the 'CategoryValues' table uses bits 5 - 6 to store the strong bidi information.

            StrongBidiCategory bidiCategory = (StrongBidiCategory)(Unsafe.AddByteOffset(ref MemoryMarshal.GetReference(CategoriesValues), offset) & 0b_0110_0000);

            Debug.Assert(bidiCategory == StrongBidiCategory.Other || bidiCategory == StrongBidiCategory.StrongLeftToRight || bidiCategory == StrongBidiCategory.StrongRightToLeft, "Unknown StrongBidiCategory value.");

            return(bidiCategory);
        }
        private static void Parse(List <CharUnicodeInfoTestCase> testCases, string line)
        {
            // Data is in the format:
            // code-value;
            // character-name;
            // general-category;
            // canonical-combining-classes; (ignored)
            // bidirecional-category; (ignored)
            // character-decomposition-mapping; (ignored)
            // decimal-digit-value; (ignored)
            // digit-value; (ignoed)
            // number-value;
            string[]           data               = line.Split(';');
            string             charValueString    = data[0];
            string             charName           = data[1];
            string             charCategoryString = data[2];
            string             numericValueString = data[8];
            StrongBidiCategory bidiCategory       = data[4] == "L" ? StrongBidiCategory.StrongLeftToRight :
                                                    data[4] == "R" || data[4] == "AL" ? StrongBidiCategory.StrongRightToLeft : StrongBidiCategory.Other;

            int codePoint = int.Parse(charValueString, NumberStyles.HexNumber);

            Parse(testCases, codePoint, charCategoryString, numericValueString, bidiCategory);

            if (charName.EndsWith("First>"))
            {
                s_rangeMinCodePoint = codePoint;
            }
            else if (charName.EndsWith("Last>"))
            {
                // Assumes that we have already found a range start
                for (int rangeCodePoint = s_rangeMinCodePoint + 1; rangeCodePoint < codePoint; rangeCodePoint++)
                {
                    // Assumes that all code points in the range have the same numeric value
                    // and general category
                    Parse(testCases, rangeCodePoint, charCategoryString, numericValueString, bidiCategory);
                }
            }
        }
        private static void Parse(List <CharUnicodeInfoTestCase> testCases, int codePoint, string charCategoryString, string numericValueString, StrongBidiCategory bidiCategory)
        {
            string          codeValueRepresentation = codePoint > char.MaxValue ? char.ConvertFromUtf32(codePoint) : ((char)codePoint).ToString();
            double          numericValue            = ParseNumericValueString(numericValueString);
            UnicodeCategory generalCategory         = s_unicodeCategories[charCategoryString];

            testCases.Add(new CharUnicodeInfoTestCase()
            {
                Utf32CodeValue  = codeValueRepresentation,
                GeneralCategory = generalCategory,
                NumericValue    = numericValue,
                CodePoint       = codePoint,
                BidiCategory    = bidiCategory
            });
        }