예제 #1
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);
        }
 // Get a hash code for this instance.
 public override int GetHashCode()
 {
     return(DecoderFallback.GetHashCode() << 24 + EncoderFallback.GetHashCode() << 16 + codePage);
 }
			// Constructor.
			public UTF8Decoder (DecoderFallback fallback)
			{
				Fallback = fallback;
				leftOverCount = 0;
				leftOverBits = 0;
			}
        public static Encoding GetEncoding(string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
        {
            if (encoderFallback == null)
            {
                throw new ArgumentNullException("encoderFallback");
            }

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

            var encoding = GetEncoding(name).Clone();

            encoding.is_readonly      = false;
            encoding.encoder_fallback = encoderFallback;
            encoding.decoder_fallback = decoderFallback;
            return(encoding);
        }
        // Determine if two Encoding objects are equal.
        public override bool Equals(object obj)
        {
            var encoding = obj as Encoding;

            return(encoding != null && codePage == encoding.codePage && DecoderFallback.Equals(encoding.DecoderFallback) && EncoderFallback.Equals(encoding.EncoderFallback));
        }
		public static Encoding GetEncoding (string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
		{
			if (encoderFallback == null)
				throw new ArgumentNullException ("encoderFallback");

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

			var encoding = GetEncoding (name).Clone ();
			encoding.is_readonly = false;
			encoding.encoder_fallback = encoderFallback;
			encoding.decoder_fallback = decoderFallback;
			return encoding;
		}
		internal void SetFallbackInternal (EncoderFallback e, DecoderFallback d)
		{
			if (e != null)
				encoder_fallback = e;

			if (d != null)
				decoder_fallback = d;
		}
        public override bool Equals(object obj)
        {
            var encoding = obj as UTF7Encoding;

            return(encoding != null && allowOptionals == encoding.allowOptionals && EncoderFallback.Equals(encoding.EncoderFallback) && DecoderFallback.Equals(encoding.DecoderFallback));
        }