Пример #1
0
        /// <summary>
        /// Prepare the unknown character for encoding
        /// </summary>
        /// <param name="unknownChar">character to process</param>
        /// <param name="index">position in input string</param>
        /// <returns>true if characters to process placed in buffer</returns>
        public override bool Fallback(char charUnknown, int index)
        {
            // if we're not done with the current buffer, we're being recursive.
            if (m_position < m_fallbackString.Length)
            {
                throw new ArgumentException(CssStringMgr.GetString(StringEnum.FallbackEncodingFailed));
            }

            // Go ahead and get our fallback
            m_fallbackString = GetEncoding((int)charUnknown);
            m_position       = 0;

            // return false if we have no string, indicating we didn't encode it
            return(m_fallbackString.Length > 0);
        }
Пример #2
0
        /// <summary>
        /// Prepare the unknwon surrogate pair for encoding
        /// </summary>
        /// <param name="unknownCharHigh">high surrogate pair character</param>
        /// <param name="unknownCharLow">low surrogate pair character</param>
        /// <param name="index">index of character in the stream</param>
        /// <returns></returns>
        public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
        {
            // if we're not done with the current buffer, we're being recursive.
            if (m_position < m_fallbackString.Length)
            {
                throw new ArgumentException(CssStringMgr.GetString(StringEnum.FallbackEncodingFailed));
            }

            // de-surrogate the pair into a single value in the range 0x010000 to 0x10ffff
            int unicodeChar = 0x10000
                              + ((int)charUnknownHigh - 0xD800) * 0x400
                              + ((int)charUnknownLow - 0xDC00);

            // validate the range?

            // get the fallback string
            m_fallbackString = GetEncoding(unicodeChar);
            m_position       = 0;

            // return false if we have no string, indicating we didn't encode it
            return(m_fallbackString.Length > 0);
        }