CreateFallbackBuffer() public abstract method

public abstract CreateFallbackBuffer ( ) : EncoderFallbackBuffer
return EncoderFallbackBuffer
        public void HandleFallback(ref EncoderFallbackBuffer buffer,
                                   char[] chars, ref int charIndex, ref int charCount,
                                   byte[] bytes, ref int byteIndex, ref int byteCount, object state)
        {
            if (buffer == null)
            {
                buffer = EncoderFallback.CreateFallbackBuffer();
            }

            if (charCount > 1 && (Char.IsSurrogate(chars[charIndex]) && Char.IsSurrogate(chars[charIndex + 1])))
            {
                buffer.Fallback(chars[charIndex], chars[charIndex + 1], charIndex);
                charIndex++;
                charCount--;
            }
            else
            {
                buffer.Fallback(chars[charIndex], charIndex);
            }

            char[] tmp = new char[buffer.Remaining];
            int    idx = 0;

            while (buffer.Remaining > 0)
            {
                tmp[idx++] = buffer.GetNextChar();
            }

            var len = state == null?
                      GetBytes(tmp, 0, tmp.Length, bytes, byteIndex)
                          : GetBytesInternal(tmp, 0, tmp.Length, bytes, byteIndex, true, state);

            byteIndex += len;
            byteCount -= len;
        }
        unsafe static char[] GetFallbackChars(char *chars, char *start, EncoderFallback fallback, ref EncoderFallbackBuffer buffer)
        {
            if (buffer == null)
            {
                buffer = fallback.CreateFallbackBuffer();
            }

            buffer.Fallback(*chars, (int)(chars - start));

            char[] fallback_chars = new char [buffer.Remaining];
            for (int i = 0; i < fallback_chars.Length; i++)
            {
                fallback_chars [i] = buffer.GetNextChar();
            }

            buffer.Reset();

            return(fallback_chars);
        }
        public unsafe void HandleFallback(ref EncoderFallbackBuffer buffer,
                                          char *chars, ref int charIndex, ref int charCount,
                                          byte *bytes, ref int byteIndex, ref int byteCount, object state)
        {
            if (buffer == null)
            {
                buffer = EncoderFallback.CreateFallbackBuffer();
            }

            if (charCount > 1 && (Char.IsSurrogate(chars [charIndex]) && Char.IsSurrogate(chars [charIndex + 1])))
            {
                buffer.Fallback(chars [charIndex], chars [charIndex + 1], charIndex);
                charIndex++;
                charCount--;
            }
            else
            {
                buffer.Fallback(chars [charIndex], charIndex);
            }

            char[] tmp = new char [buffer.Remaining];
            int    idx = 0;

            while (buffer.Remaining > 0)
                tmp [idx++] = buffer.GetNextChar();

            fixed(char *tmparr = tmp)
            {
                var outbytes = bytes == null ? null : bytes + byteIndex;
                var len      = state == null?
                               GetBytes(tmparr, tmp.Length, outbytes, byteCount)
                                   : GetBytesInternal(tmparr, tmp.Length, outbytes, byteCount, true, state);

                byteIndex += len;
                byteCount -= len;
            }
        }
Example #4
0
        unsafe int InternalGetBytes(char *chars, int charLength, int charIndex, int charCount, byte[] bytes, int byteIndex, ref EncoderFallbackBuffer buffer, ref char[] fallback_chars)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }

            if (charIndex < 0 || charIndex > charLength)
            {
                throw new ArgumentOutOfRangeException("charIndex");
            }

            if (charCount < 0 || charCount > (charLength - charIndex))
            {
                throw new ArgumentOutOfRangeException("charCount");
            }

            if (byteIndex < 0 || byteIndex > bytes.Length)
            {
                throw new ArgumentOutOfRangeException("byteIndex");
            }

            if ((bytes.Length - byteIndex) < charCount)
            {
                throw new ArgumentException("Insufficient space available.");
            }

            int  count = charCount;
            char ch;

            while (count-- > 0)
            {
                ch = chars [charIndex++];
                if (ch < (char)0x80)
                {
                    bytes [byteIndex++] = (byte)ch;
                }
                else
                {
                    if (buffer == null)
                    {
                        buffer = EncoderFallback.CreateFallbackBuffer();
                    }

                    if (Char.IsSurrogate(ch) && count > 1 && Char.IsSurrogate(chars [charIndex]))
                    {
                        buffer.Fallback(ch, chars [charIndex], charIndex++ - 1);
                    }
                    else
                    {
                        buffer.Fallback(ch, charIndex - 1);
                    }

                    if (fallback_chars == null || fallback_chars.Length < buffer.Remaining)
                    {
                        fallback_chars = new char [buffer.Remaining];
                    }

                    for (int i = 0; i < fallback_chars.Length; i++)
                    {
                        fallback_chars[i] = buffer.GetNextChar();
                    }

                    byteIndex += GetBytes(fallback_chars, 0, fallback_chars.Length, bytes, byteIndex, ref buffer, ref fallback_chars);
                }
            }
            return(charCount);
        }
		unsafe static char[] GetFallbackChars (char* chars, char* start, EncoderFallback fallback, ref EncoderFallbackBuffer buffer)
		{
			if (buffer == null)
				buffer = fallback.CreateFallbackBuffer ();

			buffer.Fallback (*chars, (int) (chars - start));

			char[] fallback_chars = new char [buffer.Remaining];
			for (int i = 0; i < fallback_chars.Length; i++)
				fallback_chars [i] = buffer.GetNextChar ();

			buffer.Reset ();

			return fallback_chars;
		}