LoSurrogate() private static method

private static LoSurrogate ( int codePoint ) : char
codePoint int
return char
Exemplo n.º 1
0
        /// <summary>
        /// This static method expands characters in a literal
        /// string, returning a modified string with character
        /// escapes replaced by the character which they denote.
        /// This includes characters outside the BMP which
        /// return a pair of surrogate characters.
        /// </summary>
        /// <param name="str">the input string</param>
        /// <returns>interpreted version of the string</returns>
        public static string InterpretCharacterEscapes(string source)
        {
            int sLen = source.Length;

            if (sLen == 0)
            {
                return(source);
            }
            char[] arr  = new char[sLen];
            int    sNxt = 0;
            int    aNxt = 0;
            char   chr  = source[sNxt++];

            for (; ; chr = source[sNxt++])
            {
                if (chr != '\\')
                {
                    arr[aNxt++] = chr;
                }
                else
                {
                    int codePoint = EscapedChar(source, ref sNxt);
                    if (codePoint > 0xFFFF)
                    {
                        arr[aNxt++] = CharacterUtilities.HiSurrogate(codePoint);
                        arr[aNxt++] = CharacterUtilities.LoSurrogate(codePoint);
                    }
                    else
                    {
                        arr[aNxt++] = (char)codePoint;
                    }
                }
                if (sNxt == sLen)
                {
                    return(new String(arr, 0, aNxt));
                }
            }
        }