UTF8toUTF16() публичный статический Метод

Utility method for #UTF8toUTF16(byte[], int, int, CharsRef)
public static UTF8toUTF16 ( BytesRef bytesRef, CharsRef chars ) : void
bytesRef BytesRef
chars CharsRef
Результат void
Пример #1
0
        /// <summary>
        /// Interprets stored bytes as UTF8 bytes, returning the
        ///  resulting string
        /// </summary>
        public string Utf8ToString()
        {
            CharsRef @ref = new CharsRef(Length);

            UnicodeUtil.UTF8toUTF16(Bytes, Offset, Length, @ref);
            return(@ref.ToString());
        }
Пример #2
0
        public virtual void TestUTF8UTF16CharsRef()
        {
            int num = AtLeast(3989);

            for (int i = 0; i < num; i++)
            {
                string   unicode = TestUtil.RandomRealisticUnicodeString(Random);
                BytesRef @ref    = new BytesRef(unicode);
                char[]   arr     = new char[1 + Random.Next(100)];
                int      offset  = Random.Next(arr.Length);
                int      len     = Random.Next(arr.Length - offset);
                CharsRef cRef    = new CharsRef(arr, offset, len);
                UnicodeUtil.UTF8toUTF16(@ref, cRef);
                Assert.AreEqual(cRef.ToString(), unicode);
            }
        }
Пример #3
0
        public static ICharSequence BytesToCharSequence(BytesRef @ref, Random random)
        {
            switch (random.Next(5))
            {
            case 4:
                CharsRef chars = new CharsRef(@ref.Length);
                UnicodeUtil.UTF8toUTF16(@ref.Bytes, @ref.Offset, @ref.Length, chars);
                return(chars);

            case 3:
                return(CharBuffer.Wrap(@ref.Utf8ToString()));

            default:
                return(new StringCharSequence(@ref.Utf8ToString()));
            }
        }