Fallback() public abstract method

public abstract Fallback ( byte bytesUnknown, int index ) : bool
bytesUnknown byte
index int
return bool
		int GetChars (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, ref DecoderFallbackBuffer buffer)
		{
			if (bytes == null)
				throw new ArgumentNullException ("bytes");

			if (chars == null) 
				throw new ArgumentNullException ("chars");

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

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

			if (charIndex < 0 || charIndex > chars.Length) 
				throw new ArgumentOutOfRangeException ("charIndex");

			if ((chars.Length - charIndex) < byteCount) 
				throw new ArgumentException ("Insufficient space available.");

			int count = byteCount;
			while (count-- > 0) {
				char c = (char) bytes [byteIndex++];
				if (c < 0x80) {
					chars [charIndex++] = c;
				} else {
					if (buffer == null)
						buffer = DecoderFallback.CreateFallbackBuffer ();

					var thisByte = new [] { bytes [byteIndex-1] };
					buffer.Fallback (thisByte, 0);

					while (buffer.Remaining > 0) {
						if (charIndex < chars.Length) {
							chars [charIndex++] = buffer.GetNextChar ();
							continue;
						}

						throw new ArgumentException ("The output char buffer is too small to contain the decoded characters.");
					}
				}
			}

			return byteCount;
		}
		// for GetChars()
		static unsafe void Fallback (object provider, ref DecoderFallbackBuffer buffer, ref byte[] bufferArg, byte* bytes, long byteIndex, uint size, char* chars, ref int charIndex)
		{
			if (buffer == null) {
				var fallback = provider as DecoderFallback;

				if (fallback != null)
					buffer = fallback.CreateFallbackBuffer ();
				else
					buffer = ((Decoder) provider).FallbackBuffer;
			}

			if (bufferArg == null)
				bufferArg = new byte [1];

			for (int i = 0; i < size; i++) {
				bufferArg [0] = bytes [byteIndex + i];
				buffer.Fallback (bufferArg, 0);
				while (buffer.Remaining > 0)
					chars [charIndex++] = buffer.GetNextChar ();
				buffer.Reset ();
			}
		}
Beispiel #3
0
        int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, ref DecoderFallbackBuffer buffer)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }

            if (chars == null)
            {
                throw new ArgumentNullException("chars");
            }

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

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

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

            if ((chars.Length - charIndex) < byteCount)
            {
                throw new ArgumentException("Insufficient space available.");
            }

            int count = byteCount;

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

                    var thisByte = new [] { bytes [byteIndex - 1] };
                    buffer.Fallback(thisByte, 0);

                    while (buffer.Remaining > 0)
                    {
                        if (charIndex < chars.Length)
                        {
                            chars [charIndex++] = buffer.GetNextChar();
                            continue;
                        }

                        throw new ArgumentException("The output char buffer is too small to contain the decoded characters.");
                    }
                }
            }

            return(byteCount);
        }
		// for GetCharCount()
		static unsafe int Fallback (object provider, ref DecoderFallbackBuffer buffer, ref byte[] bufferArg, byte* bytes, long index, uint size)
		{
			if (buffer == null) {
				var fallback = provider as DecoderFallback;

				if (fallback != null)
					buffer = fallback.CreateFallbackBuffer ();
				else
					buffer = ((Decoder) provider).FallbackBuffer;
			}

			if (bufferArg == null)
				bufferArg = new byte [1];

			int ret = 0;
			for (int i = 0; i < size; i++) {
				bufferArg [0] = bytes [(int) index + i];
				buffer.Fallback (bufferArg, 0);
				ret += buffer.Remaining;
				buffer.Reset ();
			}

			return ret;
		}