System.Text.DecoderFallbackBuffer.InternalFallback C# (CSharp) Method

InternalFallback() private method

private InternalFallback ( byte bytes, byte pBytes ) : int
bytes byte
pBytes byte
return int
        internal unsafe virtual int InternalFallback(byte[] bytes, byte* pBytes)
        {
            // Copy bytes to array (slow, but right now that's what we get to do.
//            byte[] bytesUnknown = new byte[count];
//            for (int i = 0; i < count; i++)
  //              bytesUnknown[i] = *(bytes++);

            BCLDebug.Assert(byteStart != null, "[DecoderFallback.InternalFallback]Used InternalFallback without calling InternalInitialize");

            // See if there's a fallback character and we have an output buffer then copy our string.
            if (this.Fallback(bytes, (int)(pBytes - byteStart - bytes.Length)))
            {
                int count = 0;

                char ch;
                bool bHighSurrogate = false;
                while ((ch = GetNextChar()) != 0)
                {
                    // Make sure no mixed up surrogates
                    if (Char.IsSurrogate(ch))
                    {
                        if (Char.IsHighSurrogate(ch))
                        {
                            // High Surrogate
                            if (bHighSurrogate)
                                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));
                            bHighSurrogate = true;
                        }
                        else
                        {
                            // Low surrogate
                            if (bHighSurrogate == false)
                                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));
                            bHighSurrogate = false;
                        }
                    }

                    count++;
                }

                // Need to make sure that bHighSurrogate isn't true
                if (bHighSurrogate)
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"));

                return count;
            }

            // If no fallback return 0
            return 0;
        }

Same methods

DecoderFallbackBuffer::InternalFallback ( byte bytes, byte pBytes, char &chars ) : bool

Usage Example

示例#1
0
        internal override unsafe int GetCharCount(byte *bytes, int count, DecoderNLS decoder)
        {
            DecoderReplacementFallback replacementFallback = decoder != null ? decoder.Fallback as DecoderReplacementFallback : this.DecoderFallback as DecoderReplacementFallback;

            if (replacementFallback != null && replacementFallback.MaxCharCount == 1)
            {
                return(count);
            }
            DecoderFallbackBuffer decoderFallbackBuffer = (DecoderFallbackBuffer)null;
            int num1 = count;

            byte[] bytes1 = new byte[1];
            byte * numPtr = bytes + count;

            while (bytes < numPtr)
            {
                byte num2 = *bytes;
                ++bytes;
                if ((int)num2 >= 128)
                {
                    if (decoderFallbackBuffer == null)
                    {
                        decoderFallbackBuffer = decoder != null ? decoder.FallbackBuffer : this.DecoderFallback.CreateFallbackBuffer();
                        decoderFallbackBuffer.InternalInitialize(numPtr - count, (char *)null);
                    }
                    bytes1[0] = num2;
                    num1      = num1 - 1 + decoderFallbackBuffer.InternalFallback(bytes1, bytes);
                }
            }
            return(num1);
        }
All Usage Examples Of System.Text.DecoderFallbackBuffer::InternalFallback