public void MethodGetCharInfoShouldNeverFail()
 {
     for (int i = 0; i <= 0x10FFFF; i++)
     {
         UnicodeInfo.GetCharInfo(i);
     }
 }
示例#2
0
        private static List <IndexEntry> BuildUnicodeIndex()
        {
            var sw     = Stopwatch.StartNew();
            var result = new List <IndexEntry>();
            var blocks = UnicodeInfo.GetBlocks();

            foreach (var block in blocks)
            {
                foreach (var codepoint in block.CodePointRange)
                {
                    if (char.IsSurrogate((char)codepoint))
                    {
                        continue;
                    }

                    var charInfo    = UnicodeInfo.GetCharInfo(codepoint);
                    var displayText = charInfo.Name;
                    if (displayText != null)
                    {
                        result.Add(new(charInfo, displayText, displayText.ToUpperInvariant()));
                    }
                }
            }

            Console.WriteLine("Index built in " + sw.Elapsed);
            return(result);
        }
        public static Models.CodePoint[] GetCodePoints(int offset, int limit)
        {
            if (offset < 0 || offset > 0x10FFFF)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            if (limit < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }

            var codePoints = new List <Models.CodePoint>();

            int max = Math.Min(offset + limit - 1, 0x10FFFF);

            for (int i = offset; i <= max; i++)
            {
                var charInfo = UnicodeInfo.GetCharInfo(i);

                if (charInfo.Category != UnicodeCategory.OtherNotAssigned)
                {
                    codePoints.Add(GetCodePoint(charInfo));
                }
            }

            return(codePoints.ToArray());
        }
示例#4
0
        private string GetResult(int value)
        {
            var  sb = new StringBuilder();
            char ch = (char)value;

            bool   isSurrogate = char.IsSurrogate(ch);
            string text        = null;

            if (!isSurrogate)
            {
                text = char.ConvertFromUtf32(value);
                sb.AppendLine(DivClass(Escape(text), "charSample"));
            }

            if (descriptions.TryGetValue(value, out string description))
            {
                sb.AppendLine(Div(description));
            }

            var info = UnicodeInfo.GetCharInfo(value);

            sb.AppendLine(TableStart("smallTable"));
            sb.AppendLine(Tr(Td(Gray("Code point:")), Td($"{value} (U+{value.ToHex()})")));
            sb.AppendLine(Tr(Td(Gray("Category:")), Td(CharUnicodeInfo.GetUnicodeCategory(ch).ToString())));
            sb.AppendLine(Tr(Td(Gray("Block:")), Td(info.Block)));
            sb.AppendLine(Tr(Td(Gray("Escape:")), Td(DivClass(GetEscapeString(value), "fixed"))));
            if (text != null)
            {
                sb.AppendLine(Tr(Td(Gray("UTF-8:")), Td(GetUtf8(text))));
            }

            sb.AppendLine("</table>");

            return(sb.ToString());
        }
        public void Show(FontFamily font, char glyph, string code)
        {
            lblGlyph.FontFamily = font;
            lblGlyph.Content    = glyph.ToString();
            this.Title          = $"Details - U+{code}";

            var info = UnicodeInfo.GetCharInfo(glyph);

            lblName.Content = info.Name.Replace("WITH", "\nWITH");
            lblName.ToolTip = info.Name;
            tbxCode.Text    = $"U+{code} (&#x{code};) [Alt+{Convert.ToInt32(code, 16),0:D4}]";

            if (!string.IsNullOrEmpty(info.OldName))
            {
                PrintCharInfo("Old Name", info.OldName);
            }

            PrintCharInfo("Category", info.Category.ToString());
            PrintCharInfo("Block", info.Block);
            PrintCharInfo("Canoncial Combining Class", info.CanonicalCombiningClass.ToString());
            PrintCharInfo("Bidirectional Class", info.BidirectionalClass.ToString());
            PrintCharInfo("Contributory Properties", info.ContributoryProperties.ToString());
            PrintCharInfo("Core Properties", info.CoreProperties.ToString());

            this.Show();
        }
示例#6
0
        private static void PrintCodePointInfo(int codePoint)
        {
            var charInfo = UnicodeInfo.GetCharInfo(codePoint);

            Console.WriteLine(UnicodeInfo.GetDisplayText(charInfo));
            Console.WriteLine("U+" + codePoint.ToString("X4"));
            Console.WriteLine(charInfo.Name ?? charInfo.OldName);
            Console.WriteLine(charInfo.Category);
        }
示例#7
0
        public override string ToDescriptionString()
        {
            var info = UnicodeInfo.GetCharInfo(codePoint);

            return(base.ToLongString() + "\n" +
                   "Kun: " + info.JapaneseKunReading + "\n" +
                   "On: " + info.JapaneseOnReading + "\n" +
                   info.Definition + "\n");
        }
示例#8
0
 public void RadicalUnicodeCategories()
 {
     foreach (var radical in lookup.AllRadicals)
     {
         Console.Write(radical.ToString());
         Console.Write(": ");
         var info = UnicodeInfo.GetCharInfo(radical.Utf32);
         Console.WriteLine(info.Name);
     }
 }
        public void MethodGetCharInfoShouldHaveCoherentResults()
        {
            for (int i = 0; i <= 0x10FFFF; i++)
            {
                var charInfo = UnicodeInfo.GetCharInfo(i);

                Assert.Equal(charInfo.Name, UnicodeInfo.GetName(i));
                Assert.Equal(charInfo.Category, UnicodeInfo.GetCategory(i));
                Assert.Equal(UnicodeInfo.GetDisplayText(charInfo), UnicodeInfo.GetDisplayText(i));
            }
        }
示例#10
0
        public void RadicalStrokeCountShouldHaveExpectedResults()
        {
            var char5E7A = UnicodeInfo.GetCharInfo(0x5E7A);

            Assert.NotEmpty(char5E7A.UnicodeRadicalStrokeCounts);
            Assert.False(char5E7A.UnicodeRadicalStrokeCounts[0].IsSimplified);
            Assert.Equal(52, char5E7A.UnicodeRadicalStrokeCounts[0].Radical);
            Assert.Equal(0, char5E7A.UnicodeRadicalStrokeCounts[0].StrokeCount);

            var char2A6D6 = UnicodeInfo.GetCharInfo(0x2A6D6);

            Assert.NotEmpty(char2A6D6.UnicodeRadicalStrokeCounts);
            Assert.False(char2A6D6.UnicodeRadicalStrokeCounts[0].IsSimplified);
            Assert.Equal(214, char2A6D6.UnicodeRadicalStrokeCounts[0].Radical);
            Assert.Equal(20, char2A6D6.UnicodeRadicalStrokeCounts[0].StrokeCount);
        }
示例#11
0
        public static CodePoint FromInt(int codePoint)
        {
            var info = UnicodeInfo.GetCharInfo(codePoint);

            switch (info.Block)
            {
            case "Hiragana":
                return(new Hiragana(codePoint));

            case "Katakana":
                return(new Katakana(codePoint));

            case "CJK Unified Ideographs":
                return(new Kanji(codePoint));

            default:
                return(new CodePoint(codePoint));
            }
        }
示例#12
0
        public void CharacterInfoShouldHaveExpectedResults(int codePoint, UnicodeCategory expectedCategory, UnicodeNumericType expectedNumericType, string expectedNumericValue, string expectedName, string expectedBlock)
        {
            var info = UnicodeInfo.GetCharInfo(codePoint);

            Assert.Equal(codePoint, info.CodePoint);
            Assert.Equal(expectedCategory, info.Category);
            Assert.Equal(expectedNumericType, info.NumericType);
            if (expectedNumericValue != null)
            {
                Assert.Equal(UnicodeRationalNumber.Parse(expectedNumericValue), info.NumericValue);
            }
            else
            {
                Assert.Null(info.NumericValue);
            }
            Assert.Equal(expectedName, info.Name);
            Assert.Equal(expectedBlock, UnicodeInfo.GetBlockName(codePoint));
            Assert.Equal(expectedBlock, info.Block);
        }
示例#13
0
        private void Initialize()
        {
            var builder = new IndexBuilder();

            for (int i = 0; i <= 0x10FFFF; i++)
            {
                var    charInfo = UnicodeInfo.GetCharInfo(i);
                string name     = charInfo.Name;

                if (!string.IsNullOrEmpty(name))
                {
                    foreach (string word in name.Split(i == 0x1180 ? SimplifiedWordSeparators : WordSeparators))
                    {
                        builder.AddWord(word, i);
                    }
                }

                if (!string.IsNullOrEmpty(charInfo.OldName))
                {
                    foreach (string word in RemoveForbiddenCharacters(charInfo.OldName).Split(WordSeparators))
                    {
                        builder.AddWord(word, i);
                    }
                }

                if (charInfo.NameAliases.Count > 0)
                {
                    foreach (var nameAlias in charInfo.NameAliases)
                    {
                        foreach (string word in nameAlias.Name.Split(WordSeparators))
                        {
                            builder.AddWord(word, i);
                        }
                    }
                }
            }

            _wordIndex = builder.Build();

            GC.Collect();
        }
示例#14
0
        private void BuildUnicodeList()
        {
            var blocks = UnicodeInfo.GetBlocks();

            foreach (var block in blocks)
            {
                foreach (var codepoint in block.CodePointRange)
                {
                    if (char.IsSurrogate((char)codepoint))
                    {
                        continue;
                    }

                    var charInfo    = UnicodeInfo.GetCharInfo(codepoint);
                    var displayText = charInfo.Name;
                    if (displayText != null)
                    {
                        descriptions[codepoint] = displayText;
                    }
                }
            }
        }
示例#15
0
        private void blockSelection_SelectedIndexChanged(object sender, EventArgs e)
        {
            charView.Items.Clear();
            UnicodeBlock    newB        = UnicodeInfo.GetBlocks()[blockSelection.SelectedIndex];
            int             i           = newB.CodePointRange.FirstCodePoint;
            int             range_upper = newB.CodePointRange.LastCodePoint;
            UnicodeCharInfo uc          = new UnicodeCharInfo();
            int             itemind     = 0;
            string          name        = "RESERVED CODEPOINT";

            while (i <= range_upper)
            {
                uc = UnicodeInfo.GetCharInfo(i);
                charView.Items.Add(UnicodeInfo.GetDisplayText(uc));
                if (uc.Name != null)
                {
                    name = uc.Name;
                }
                charView.Items[itemind].ToolTipText = name + "\r\nCode point: U+" + BitConverter.ToString(BitConverter.GetBytes(uc.CodePoint).Reverse().ToArray()).Replace("-", "");
                i++;
                itemind++;
            }
        }
        static void Main(string[] args)
        {
            //https://docs.microsoft.com/ja-jp/dotnet/api/system.char?view=netcore-3.1#Relationship
            //https://github.com/GoldenCrystal/NetUnicodeInfo

            if (args.Length != 2)
            {
                Environment.Exit(0);
            }

            int s = int.Parse(args[0]);
            int e = int.Parse(args[1]);

            if (s > e)
            {
                Environment.Exit(0);
            }

            int c = e - s + 1;

            if (s < 0)
            {
                Environment.Exit(0);
            }
            if (e < 0 || e > 1114112)
            {
                Environment.Exit(0);
            }
            if (c < 0 || c > 1114112)
            {
                Environment.Exit(0);
            }

            List <int> lowerCodePointList = Enumerable.Range(s, c).Where(i => i < 55296).ToList();
            List <int> upperCodePointList = Enumerable.Range(s, c).Where(i => i > 57343).ToList();

            List <int> codePointList = new List <int> ();

            if (0 != lowerCodePointList.Count)
            {
                codePointList.AddRange(lowerCodePointList);
            }
            if (0 != upperCodePointList.Count)
            {
                codePointList.AddRange(upperCodePointList);
            }

            if (0 == codePointList.Count)
            {
                Environment.Exit(0);
            }

            int grp = 0;

            List <Dictionary <string, string> > summaryList = new List <Dictionary <string, string> > ();

            foreach (var codePoint in codePointList)
            {
                grp++;

                string item = Char.ConvertFromUtf32(codePoint);

                List <char> charList = item.ToCharArray().ToList();

                var charInfo = UnicodeInfo.GetCharInfo(codePoint);

                int grpseq = 0;

                foreach (Char ch in charList)
                {
                    Dictionary <string, string> detailDict = new Dictionary <string, string> ();

                    grpseq++;

                    detailDict.Add(GRP, grp.ToString());
                    detailDict.Add(GRPSEQ, grpseq.ToString());
                    detailDict.Add(CODEPOINT, codePoint.ToString());
                    detailDict.Add(GRAPH, item);
                    detailDict.Add(NAME, charInfo.Name);
                    detailDict.Add(NUMERIC_VALUE, charInfo.NumericValue.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : charInfo.NumericValue.ToString());
                    detailDict.Add(BIDIRECTIONAL_CLASS, charInfo.BidirectionalClass.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : charInfo.BidirectionalClass.ToString());
                    detailDict.Add(BIDIRECTIONAL_MIRRORED, charInfo.BidirectionalMirrored.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : charInfo.BidirectionalMirrored.ToString());
                    detailDict.Add(BLOCK, charInfo.Block.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : charInfo.Block.ToString());
                    detailDict.Add(CANONICAL_COMBINING_CLASS, charInfo.CanonicalCombiningClass.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : charInfo.CanonicalCombiningClass.ToString());
                    detailDict.Add(CANTONESE_READING, charInfo.CantoneseReading == null ? DEFAULT_NONE_STRING_VALUE : charInfo.CantoneseReading);
                    detailDict.Add(CATEGORY, charInfo.Category.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : charInfo.Category.ToString());
                    detailDict.Add(DECOMPOSITION_MAPPING, charInfo.DecompositionMapping == null ? DEFAULT_NONE_STRING_VALUE : charInfo.DecompositionMapping);
                    detailDict.Add(DECOMPOSITION_TYPE, charInfo.DecompositionType.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : charInfo.DecompositionType.ToString());
                    detailDict.Add(DEFINITION, charInfo.Definition == null ? DEFAULT_NONE_STRING_VALUE : charInfo.Definition);
                    detailDict.Add(HANGUL_READING, charInfo.HangulReading == null ? DEFAULT_NONE_STRING_VALUE : charInfo.HangulReading);
                    detailDict.Add(JAPANESE_KUN_READING, charInfo.JapaneseKunReading == null ? DEFAULT_NONE_STRING_VALUE : charInfo.JapaneseKunReading);
                    detailDict.Add(JAPANESE_ON_READING, charInfo.JapaneseOnReading == null ? DEFAULT_NONE_STRING_VALUE : charInfo.JapaneseOnReading);
                    detailDict.Add(KOREAN_READING, charInfo.KoreanReading == null ? DEFAULT_NONE_STRING_VALUE : charInfo.KoreanReading);
                    detailDict.Add(MANDARIN_READING, charInfo.MandarinReading == null ? DEFAULT_NONE_STRING_VALUE : charInfo.MandarinReading);
                    detailDict.Add(ALIAS_NAME, String.Join(ITEM_JOINER, charInfo.NameAliases.Select(unicodeNameAlias => unicodeNameAlias.Name == null ? DEFAULT_NONE_STRING_VALUE : unicodeNameAlias.Name).ToArray()));
                    detailDict.Add(ALIAS_KIND, String.Join(ITEM_JOINER, charInfo.NameAliases.Select(unicodeNameAlias => unicodeNameAlias.Kind.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : unicodeNameAlias.Kind.ToString()).ToArray()));
                    detailDict.Add(NUMERIC_TYPE, charInfo.NumericType.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : charInfo.NumericType.ToString());
                    detailDict.Add(OLD_NAME, charInfo.OldName == null ? DEFAULT_NONE_STRING_VALUE : charInfo.OldName);
                    detailDict.Add(SIMPLE_LOWER_CASE_MAPPING, charInfo.SimpleLowerCaseMapping == null ? DEFAULT_NONE_STRING_VALUE : charInfo.SimpleLowerCaseMapping);
                    detailDict.Add(SIMPLE_TITLE_CASE_MAPPING, charInfo.SimpleTitleCaseMapping == null ? DEFAULT_NONE_STRING_VALUE : charInfo.SimpleTitleCaseMapping);
                    detailDict.Add(SIMPLE_UPPER_CASE_MAPPING, charInfo.SimpleUpperCaseMapping == null ? DEFAULT_NONE_STRING_VALUE : charInfo.SimpleUpperCaseMapping);
                    detailDict.Add(SIMPLIFIED_VARIANT, charInfo.SimplifiedVariant == null ? DEFAULT_NONE_STRING_VALUE : charInfo.SimplifiedVariant);
                    detailDict.Add(TRADITIONAL_VARIANT, charInfo.TraditionalVariant == null ? DEFAULT_NONE_STRING_VALUE : charInfo.TraditionalVariant);
                    detailDict.Add(UNICODE_RADICAL_STROKE_COUNTS, String.Join(ITEM_JOINER, charInfo.UnicodeRadicalStrokeCounts.Select(unicodeRadicalStrokeCount => unicodeRadicalStrokeCount.Radical.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : unicodeRadicalStrokeCount.Radical.ToString()).ToArray()));
                    detailDict.Add(VIETNAMESE_READING, charInfo.VietnameseReading == null ? DEFAULT_NONE_STRING_VALUE : charInfo.VietnameseReading);
                    detailDict.Add(IS_ASCII, String.Join(ITEM_JOINER, item.EnumerateRunes().Select(rune => rune.IsAscii.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : rune.IsAscii.ToString()).ToArray()));
                    detailDict.Add(IS_BMP, String.Join(ITEM_JOINER, item.EnumerateRunes().Select(rune => rune.IsBmp.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : rune.IsBmp.ToString()).ToArray()));
                    detailDict.Add(PLANE, String.Join(ITEM_JOINER, item.EnumerateRunes().Select(rune => rune.Plane.ToString() == "" ? DEFAULT_NONE_STRING_VALUE : rune.Plane.ToString()).ToArray()));

                    summaryList.Add(detailDict);
                }
            }

            //header
            Console.WriteLine(String.Join(FS, summaryList[0].Keys.ToArray()));

            //body
            foreach (var itemDict in summaryList)
            {
                List <string> keyList = itemDict.Keys.ToList();

                foreach (var key in keyList)
                {
                    {
                        Console.Write(itemDict[key]);
                        Console.Write(FS);
                    }
                }

                Console.WriteLine();
            }
        }
 public static Models.CodePoint GetCodePoint(int codePoint) => GetCodePoint(UnicodeInfo.GetCharInfo(codePoint));
示例#18
0
        public static ICollection <CharInfoWrapper> GetData(string search)
        {
            if (search.Length == 0)
            {
                return(Array.Empty <CharInfoWrapper>());
            }

            if (search.Length == 1)
            {
                return new[] { new CharInfoWrapper(UnicodeInfo.GetCharInfo(search[0])) }
            }
            ;

            if (search.Length == 2 && char.IsHighSurrogate(search[0]) && char.IsLowSurrogate(search[1]))
            {
                return new[] { new CharInfoWrapper(UnicodeInfo.GetCharInfo(char.ConvertToUtf32(search[0], search[1]))) }
            }
            ;

            int code;

            if (search.StartsWith("\\u", StringComparison.OrdinalIgnoreCase) || search.StartsWith("U+", StringComparison.OrdinalIgnoreCase) || search.StartsWith("&#", StringComparison.OrdinalIgnoreCase))
            {
                var value = search.Substring(2);

                if (int.TryParse(value, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out code))
                {
                    return new[] { new CharInfoWrapper(UnicodeInfo.GetCharInfo(code)) }
                }
                ;
            }

            if (int.TryParse(search, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out code))
            {
                return new[] { new CharInfoWrapper(UnicodeInfo.GetCharInfo(code)) }
            }
            ;

            // Search by description
            if (s_index == null)
            {
                s_index = BuildUnicodeIndex();
            }

            var result = new List <CharInfoWrapper>();

            search = search.ToUpperInvariant();
            foreach (var entry in s_index)
            {
                if (entry.Text.Contains(search, StringComparison.Ordinal))
                {
                    result.Add(new CharInfoWrapper(entry.CharInfo));

                    if (result.Count > 100)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
示例#19
0
 public void ControlCharactersShouldHaveSpecificDisplayText()
 {
     for (int i = 0; i <= 0x20; ++i)
     {
         Assert.Equal(char.ConvertFromUtf32(0x2400 + i), UnicodeInfo.GetDisplayText(i));
         Assert.Equal(char.ConvertFromUtf32(0x2400 + i), UnicodeInfo.GetDisplayText(UnicodeInfo.GetCharInfo(i)));
     }
 }
示例#20
0
 [InlineData(0xE007F, EmojiProperties.ExtendedPictographic)] // CANCEL TAG
 public void CodePointShouldNotHaveEmojiProperties(int codePoint, EmojiProperties emojiProperties)
 => Assert.Equal((EmojiProperties)0, UnicodeInfo.GetCharInfo(codePoint).EmojiProperties & emojiProperties);
示例#21
0
 [InlineData(0xE01EF, CoreProperties.ExtendedIdentifierContinue)] // VARIATION SELECTOR-256
 public void CodePointShouldHaveCoreProperties(int codePoint, CoreProperties coreProperties)
 => Assert.Equal(coreProperties, UnicodeInfo.GetCharInfo(codePoint).CoreProperties & coreProperties);