Exemplo n.º 1
0
        private static List <CharRangeItem> ReadUnicodeCharRangesFromFile(string path)
        {
            string[]             lines = System.IO.File.ReadAllLines(path);
            List <CharRangeItem> unicodeCharRangesFromFile = new List <CharRangeItem>();

            foreach (string line in lines)
            {
                var words         = line.Split(' ');
                var charRangeItem = new CharRangeItem();
                charRangeItem.StartIndex = Convert.ToInt32(words[1], 16);
                charRangeItem.EndIndex   = Convert.ToInt32(words[2], 16);
                charRangeItem.Type       = (Enums.UnicodeType)Enum.Parse(typeof(Enums.UnicodeType), words[0]);
                unicodeCharRangesFromFile.Add(charRangeItem);
            }
            return(unicodeCharRangesFromFile);
        }
Exemplo n.º 2
0
        public static string GetRandomText(Enums.TextType textType, uint characterNumber)
        {
            CharRangeItem charRangeItem = new CharRangeItem();

            switch (textType)
            {
            case Enums.TextType.BasicLatin:
                charRangeItem = GetUnicodeRange(Enums.UnicodeType.BasicLatin);
                break;

            case Enums.TextType.AsciiExtented:
                charRangeItem = GetUnicodeRange(Enums.UnicodeType.Latin1Supplement);
                break;

            case Enums.TextType.Hiragana:
                charRangeItem = GetUnicodeRange(Enums.UnicodeType.Hiragana);
                break;

            case Enums.TextType.Katakana:
                charRangeItem = GetUnicodeRange(Enums.UnicodeType.Katakana);
                break;

            case Enums.TextType.Kanji:
                charRangeItem = GetUnicodeRange(Enums.UnicodeType.KangxiRadicals);
                break;

            case Enums.TextType.Cyrillic:
                charRangeItem = GetUnicodeRange(Enums.UnicodeType.Cyrillic);
                break;
            }

            int        charCodesRange = charRangeItem.EndIndex - charRangeItem.StartIndex;
            List <int> characterSet   = Enumerable.Range(charRangeItem.StartIndex, charCodesRange).ToList();

            StringBuilder result = new StringBuilder();

            for (uint i = 0; i < characterNumber; i++)
            {
                result.Append(Convert.ToChar(characterSet[GetRandomNumber(charCodesRange)]));
            }
            return(result.ToString());
        }