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