Ejemplo n.º 1
0
        /// <summary>
        /// Reads all scalar values from the specified input string.
        /// </summary>
        /// <param name="inputString">The string to read values from.</param>
        /// <returns>An array of scalar values contained in the string.</returns>
        private static int[] ReadAllScalarValues(string inputString)
        {
            Utf16StringReader stringReader = new Utf16StringReader(inputString);
            List <int>        retVal       = new List <int>();

            while (true)
            {
                int nextValue = stringReader.ReadNextScalarValue();
                if (nextValue < 0)
                {
                    return(retVal.ToArray());
                }

                retVal.Add(nextValue);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the next scalar value from the input string.
        /// </summary>
        /// <returns>The next scalar value. If the input string contains invalid UTF-16, the
        /// return value is the Unicode replacement character U+FFFD. If the end of the string
        /// is reached, returns -1.</returns>
        public int ReadNextScalarValue()
        {
            if (this.currentOffset >= this.input.Length)
            {
                return(-1);
            }
            char c   = this.input[this.currentOffset++];
            int  num = (int)c;

            if (char.IsHighSurrogate(c) && this.currentOffset < this.input.Length)
            {
                char c2 = this.input[this.currentOffset];
                if (char.IsLowSurrogate(c2))
                {
                    this.currentOffset++;
                    num = Utf16StringReader.ConvertToUtf32(c, c2);
                }
            }
            if (Utf16StringReader.IsValidUnicodeScalarValue(num))
            {
                return(num);
            }
            return(65533);
        }