コード例 #1
0
        public static Rune FromString(string value, ref int index)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (index >= value.Length)
            {
                throw new ArgumentOutOfRangeException("index", "Index is out of range of string.");
            }

            char c = value[index++];

            if (Utf16.IsLeadingSurrogate(c))
            {
                if (index >= value.Length)
                {
                    throw new ArgumentOutOfRangeException("index", "Index is out of range of string.");
                }

                char d = value[index++];

                return(Rune.FromUtf16(c, d));
            }
            else
            {
                return(Rune.FromUtf16(c));
            }
        }
コード例 #2
0
        public static Rune FromUtf16(ushort[] array, ref int index)
        {
            if (index >= array.Length)
            {
                throw new ArgumentOutOfRangeException("index", "Index out of bounds.");
            }

            var value = array[index++];

            if (Utf16.IsLeadingSurrogate(value))
            {
                if (index >= array.Length)
                {
                    throw new ArgumentOutOfRangeException("index", "Need two items to process surrogate pair.");
                }

                var trailing = array[index++];

                return(FromUtf16(value, trailing));
            }
            else
            {
                return(new Rune(value));
            }
        }