Exemplo n.º 1
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetBytesCommon
        private protected sealed override unsafe int GetBytesFast(char *pChars, int charsLength, byte *pBytes, int bytesLength, out int charsConsumed)
        {
            int bytesWritten = (int)Latin1Utility.NarrowUtf16ToLatin1(pChars, pBytes, (uint)Math.Min(charsLength, bytesLength));

            charsConsumed = bytesWritten;
            return(bytesWritten);
        }
Exemplo n.º 2
0
        // called by the fallback mechanism
        private protected sealed override unsafe int GetCharsFast(byte *pBytes, int bytesLength, char *pChars, int charsLength, out int bytesConsumed)
        {
            int charsWritten = Math.Min(bytesLength, charsLength);

            Latin1Utility.WidenLatin1ToUtf16(pBytes, pChars, (uint)charsWritten);

            bytesConsumed = charsWritten;
            return(charsWritten);
        }
Exemplo n.º 3
0
        [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetByteCountCommon
        private protected sealed override unsafe int GetByteCountFast(char *pChars, int charsLength, EncoderFallback?fallback, out int charsConsumed)
        {
            // Can we short-circuit the entire calculation? If so, the output byte count
            // will exactly match the input char count. Otherwise we need to walk the
            // entire input and find the index of the first non-Latin-1 char.

            int byteCount = charsLength;

            if (!FallbackSupportsFastGetByteCount(fallback))
            {
                // Unrecognized fallback mechanism - count chars manually.

                byteCount = (int)Latin1Utility.GetIndexOfFirstNonLatin1Char(pChars, (uint)charsLength);
            }

            charsConsumed = byteCount;
            return(byteCount);
        }
Exemplo n.º 4
0
        private unsafe int GetCharsCommon(byte *pBytes, int byteCount, char *pChars, int charCount)
        {
            // Common helper method for all non-DecoderNLS entry points to GetChars.
            // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.

            Debug.Assert(byteCount >= 0, "Caller shouldn't specify negative length buffer.");
            Debug.Assert(pBytes != null || byteCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
            Debug.Assert(charCount >= 0, "Caller shouldn't specify negative length buffer.");
            Debug.Assert(pChars != null || charCount == 0, "Input pointer shouldn't be null if non-zero length specified.");

            // If we already know ahead of time that the destination buffer isn't large enough to hold
            // the widened data, fail immediately.

            if (byteCount > charCount)
            {
                ThrowCharsOverflow();
            }

            Latin1Utility.WidenLatin1ToUtf16(pBytes, pChars, (uint)byteCount);
            return(byteCount);
        }