System.Xml.UTF16Decoder.Convert C# (CSharp) Méthode

Convert() public méthode

public Convert ( byte bytes, int byteIndex, int byteCount, char chars, int charIndex, int charCount, bool flush, int &bytesUsed, int &charsUsed, bool &completed ) : void
bytes byte
byteIndex int
byteCount int
chars char
charIndex int
charCount int
flush bool
bytesUsed int
charsUsed int
completed bool
Résultat void
        public override void Convert( byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed ) {
            charsUsed = 0;
            bytesUsed = 0;

            if ( lastByte >= 0 ) {
                if ( byteCount == 0 ) {
                    completed = true;
                    return;
                }
                int nextByte = bytes[byteIndex++];
                byteCount--;
                bytesUsed++;

                chars[charIndex++] = bigEndian
                    ? (char)( lastByte << 8 | nextByte )
                    : (char)( nextByte << 8 | lastByte );
                charCount--;
                charsUsed++;
                lastByte = -1;
            }

            if ( charCount * CharSize < byteCount ) {
                byteCount = charCount * CharSize;
                completed = false;
            }
            else {
                completed = true;
            }

            if ( bigEndian == BitConverter.IsLittleEndian ) {
                int i = byteIndex;
                int byteEnd = i + ( byteCount & ~0x1 );
                if ( bigEndian ) {
                    while ( i < byteEnd ) {
                        int hi = bytes[i++];
                        int lo = bytes[i++];
                        chars[charIndex++] = (char)( hi << 8 | lo );
                    }                    
                }
                else {
                    while ( i < byteEnd ) {
                        int lo = bytes[i++];
                        int hi = bytes[i++];
                        chars[charIndex++] = (char)( hi << 8 | lo );
                    }
                }
            }
            else {
                Buffer.BlockCopy( bytes, byteIndex, chars, charIndex * CharSize, (int)(byteCount & ~0x1) );
            }
            charsUsed += byteCount / CharSize;
            bytesUsed += byteCount;
            
            if ( ( byteCount & 1 ) != 0 ) {
                lastByte = bytes[byteIndex + byteCount - 1];
            }
        }
    }