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

InternalFallback() private method

private InternalFallback ( byte bytes, byte pBytes, char &chars ) : bool
bytes byte
pBytes byte
chars char
return bool
        internal unsafe virtual bool InternalFallback(byte[] bytes, byte* pBytes, ref char* chars)
        {
            // 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)))
            {
                // Copy the chars to our output
                char ch;
                char* charTemp = chars;
                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;
                        }
                    }

                    if (charTemp >= charEnd)
                    {
                        // No buffer space
                        return false;
                    }

                    *(charTemp++) = ch;
                }

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

                // Now we aren't going to be false, so its OK to update chars
                chars = charTemp;
            }

            return true;
        }

Same methods

DecoderFallbackBuffer::InternalFallback ( byte bytes, byte pBytes ) : int

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