Beispiel #1
0
 private static async Task ProcessEmojiDataFile(IDataSource emojiSource, UnicodeInfoBuilder builder)
 {
     using (var reader = new UnicodeDataFileReader(await emojiSource.OpenDataFileAsync(EmojiDataFileName).ConfigureAwait(false), ';'))
     {
         while (reader.MoveToNextLine())
         {
             var range = UnicodeCodePointRange.Parse(reader.ReadTrimmedField());
             if (EnumHelper <EmojiProperties> .TryGetNamedValue(reader.ReadTrimmedField(), out var property))
             {
                 builder.SetProperties(property, range);
             }
         }
     }
 }
Beispiel #2
0
        private static async Task ProcessCjkRadicalsFile(IDataSource ucdSource, UnicodeInfoBuilder builder)
        {
            using (var reader = new UnicodeDataFileReader(await ucdSource.OpenDataFileAsync(CjkRadicalsFileName).ConfigureAwait(false), ';'))
            {
                int lastReadRadical = 0;

                while (reader.MoveToNextLine())
                {
                    string radicalIndexText = reader.ReadField();
                    bool   isSimplified     = radicalIndexText[radicalIndexText.Length - 1] == '\'';
                    int    radicalIndex     = int.Parse(isSimplified ? radicalIndexText.Substring(0, radicalIndexText.Length - 1) : radicalIndexText);

                    if (isSimplified ? radicalIndex != lastReadRadical : lastReadRadical + 1 != (lastReadRadical = radicalIndex))
                    {
                        throw new InvalidDataException("Did not expect radical number " + radicalIndexText + ".");
                    }

                    char radicalCodePoint   = checked ((char)int.Parse(reader.ReadTrimmedField(), NumberStyles.HexNumber));
                    char characterCodePoint = checked ((char)int.Parse(reader.ReadTrimmedField(), NumberStyles.HexNumber));

                    if (!isSimplified && (radicalCodePoint & 0x8000) != 0)
                    {
                        throw new InvalidOperationException("Did not expect the radical code point to be higher than U+8000 for radical " + radicalIndex.ToString() + ".");
                    }

                    if (isSimplified)
                    {
                        builder.SetRadicalInfo(radicalIndex, UpdateRadicalData(builder.GetRadicalInfo(radicalIndex), radicalCodePoint, characterCodePoint));
                    }
                    else
                    {
                        builder.SetRadicalInfo(radicalIndex, new CjkRadicalData(radicalCodePoint, characterCodePoint));
                    }
                }

                if (lastReadRadical != UnicodeInfoBuilder.CjkRadicalCount)
                {
                    throw new InvalidOperationException("There was not enough data for the 214 CJK radicals.");
                }
            }
        }
Beispiel #3
0
 private static async Task ProcessBlocksFile(IDataSource ucdSource, UnicodeInfoBuilder builder)
 {
     using (var reader = new UnicodeDataFileReader(await ucdSource.OpenDataFileAsync(BlocksFileName).ConfigureAwait(false), ';'))
     {
         while (reader.MoveToNextLine())
         {
             builder.AddBlockEntry(new UnicodeBlock(UnicodeCodePointRange.Parse(reader.ReadField()), reader.ReadTrimmedField()));
         }
     }
 }