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;
}