System.Xml.XmlInputStream.GetStringFromBytes C# (CSharp) Méthode

GetStringFromBytes() static private méthode

static private GetStringFromBytes ( byte bytes, int index, int count ) : string
bytes byte
index int
count int
Résultat string
		static string GetStringFromBytes (byte [] bytes, int index, int count)
		{
#if NET_2_1 && !MONOTOUCH
			char [] chars = new char [count];
			for (int i = index; i < count; i++)
				chars [i] = (char) bytes [i];

			return new string (chars);
#else
			return Encoding.ASCII.GetString (bytes, index, count);
#endif
		}

Usage Example

        private void Initialize(Stream stream)
        {
            this.buffer    = new byte[64];
            this.stream    = stream;
            this.enc       = XmlInputStream.StrictUTF8;
            this.bufLength = stream.Read(this.buffer, 0, this.buffer.Length);
            if (this.bufLength == -1 || this.bufLength == 0)
            {
                return;
            }
            int i   = this.ReadByteSpecial();
            int num = i;

            if (num != 254)
            {
                if (num != 255)
                {
                    if (num != 60)
                    {
                        if (num != 239)
                        {
                            this.bufPos = 0;
                        }
                        else
                        {
                            i = this.ReadByteSpecial();
                            if (i == 187)
                            {
                                i = this.ReadByteSpecial();
                                if (i != 191)
                                {
                                    this.bufPos = 0;
                                }
                            }
                            else
                            {
                                this.buffer[--this.bufPos] = 239;
                            }
                        }
                    }
                    else
                    {
                        if (this.bufLength >= 5 && XmlInputStream.GetStringFromBytes(this.buffer, 1, 4) == "?xml")
                        {
                            this.bufPos += 4;
                            i            = this.SkipWhitespace();
                            if (i == 118)
                            {
                                while (i >= 0)
                                {
                                    i = this.ReadByteSpecial();
                                    if (i == 48)
                                    {
                                        this.ReadByteSpecial();
                                        break;
                                    }
                                }
                                i = this.SkipWhitespace();
                            }
                            if (i == 101)
                            {
                                int num2 = this.bufLength - this.bufPos;
                                if (num2 >= 7 && XmlInputStream.GetStringFromBytes(this.buffer, this.bufPos, 7) == "ncoding")
                                {
                                    this.bufPos += 7;
                                    i            = this.SkipWhitespace();
                                    if (i != 61)
                                    {
                                        throw XmlInputStream.encodingException;
                                    }
                                    i = this.SkipWhitespace();
                                    int           num3          = i;
                                    StringBuilder stringBuilder = new StringBuilder();
                                    for (;;)
                                    {
                                        i = this.ReadByteSpecial();
                                        if (i == num3)
                                        {
                                            break;
                                        }
                                        if (i < 0)
                                        {
                                            goto Block_19;
                                        }
                                        stringBuilder.Append((char)i);
                                    }
                                    string text = stringBuilder.ToString();
                                    if (!XmlChar.IsValidIANAEncoding(text))
                                    {
                                        throw XmlInputStream.encodingException;
                                    }
                                    this.enc = Encoding.GetEncoding(text);
                                    goto IL_272;
Block_19:
                                    throw XmlInputStream.encodingException;
                                }
                            }
                        }
IL_272:
                        this.bufPos = 0;
                    }
                }
                else
                {
                    i = this.ReadByteSpecial();
                    if (i == 254)
                    {
                        this.enc = Encoding.Unicode;
                    }
                    else
                    {
                        this.bufPos = 0;
                    }
                }
            }
            else
            {
                i = this.ReadByteSpecial();
                if (i == 255)
                {
                    this.enc = Encoding.BigEndianUnicode;
                    return;
                }
                this.bufPos = 0;
            }
        }