[System.Security.SecurityCritical] // auto-generated internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS decoder) { // Just need to ASSERT, this is called by something else internal that checked parameters already Contract.Assert(bytes != null, "[SBCSCodePageEncoding.GetChars]bytes is null"); Contract.Assert(byteCount >= 0, "[SBCSCodePageEncoding.GetChars]byteCount is negative"); Contract.Assert(chars != null, "[SBCSCodePageEncoding.GetChars]chars is null"); Contract.Assert(charCount >= 0, "[SBCSCodePageEncoding.GetChars]charCount is negative"); CheckMemorySection(); // See if we have best fit bool bUseBestFit = false; // Do it fast way if using ? replacement or best fit fallbacks byte *byteEnd = bytes + byteCount; byte *byteStart = bytes; char *charStart = chars; // Only need decoder fallback buffer if not using default replacement fallback or best fit fallback. DecoderReplacementFallback fallback = null; if (decoder == null) { fallback = this.DecoderFallback as DecoderReplacementFallback; bUseBestFit = this.DecoderFallback.IsMicrosoftBestFitFallback; } else { fallback = decoder.Fallback as DecoderReplacementFallback; bUseBestFit = decoder.Fallback.IsMicrosoftBestFitFallback; Contract.Assert(!decoder.m_throwOnOverflow || !decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0, "[SBCSCodePageEncoding.GetChars]Expected empty fallback buffer at start"); } if (bUseBestFit || (fallback != null && fallback.MaxCharCount == 1)) { // Try it the fast way char replacementChar; if (fallback == null) { replacementChar = '?'; // Best fit alwasy has ? for fallback for SBCS } else { replacementChar = fallback.DefaultString[0]; } // Need byteCount chars, otherwise too small buffer if (charCount < byteCount) { // Need at least 1 output byte, throw if must throw ThrowCharsOverflow(decoder, charCount < 1); // Not throwing, use what we can byteEnd = bytes + charCount; } // Quick loop, just do '?' replacement because we don't have fallbacks for decodings. while (bytes < byteEnd) { char c; if (bUseBestFit) { if (arrayBytesBestFit == null) { ReadBestFitTable(); } c = arrayBytesBestFit[*bytes]; } else { c = mapBytesToUnicode[*bytes]; } bytes++; if (c == UNKNOWN_CHAR) { // This is an invalid byte in the ASCII encoding. *chars = replacementChar; } else { *chars = c; } chars++; } // bytes & chars used are the same if (decoder != null) { decoder.m_bytesUsed = (int)(bytes - byteStart); } return((int)(chars - charStart)); } // Slower way's going to need a fallback buffer DecoderFallbackBuffer fallbackBuffer = null; byte[] byteBuffer = new byte[1]; char * charEnd = chars + charCount; // Not quite so fast loop while (bytes < byteEnd) { // Faster if don't use *bytes++; char c = mapBytesToUnicode[*bytes]; bytes++; // See if it was unknown if (c == UNKNOWN_CHAR) { // Make sure we have a fallback buffer if (fallbackBuffer == null) { if (decoder == null) { fallbackBuffer = this.DecoderFallback.CreateFallbackBuffer(); } else { fallbackBuffer = decoder.FallbackBuffer; } fallbackBuffer.InternalInitialize(byteEnd - byteCount, charEnd); } // Use fallback buffer Contract.Assert(bytes > byteStart, "[SBCSCodePageEncoding.GetChars]Expected bytes to have advanced already (unknown byte)"); byteBuffer[0] = *(bytes - 1); // Fallback adds fallback to chars, but doesn't increment chars unless the whole thing fits. if (!fallbackBuffer.InternalFallback(byteBuffer, bytes, ref chars)) { // May or may not throw, but we didn't get this byte bytes--; // unused byte fallbackBuffer.InternalReset(); // Didn't fall this back ThrowCharsOverflow(decoder, bytes == byteStart); // throw? break; // don't throw, but stop loop } } else { // Make sure we have buffer space if (chars >= charEnd) { Contract.Assert(bytes > byteStart, "[SBCSCodePageEncoding.GetChars]Expected bytes to have advanced already (known byte)"); bytes--; // unused byte ThrowCharsOverflow(decoder, bytes == byteStart); // throw? break; // don't throw, but stop loop } *(chars) = c; chars++; } } // Might have had decoder fallback stuff. if (decoder != null) { decoder.m_bytesUsed = (int)(bytes - byteStart); } // Expect Empty fallback buffer for GetChars Contract.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0, "[SBCSEncoding.GetChars]Expected Empty fallback buffer at end"); return((int)(chars - charStart)); }
[System.Security.SecurityCritical] // auto-generated internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS decoder) { // Just need to ASSERT, this is called by something else internal that checked parameters already Contract.Assert(bytes != null, "[ASCIIEncoding.GetChars]bytes is null"); Contract.Assert(byteCount >= 0, "[ASCIIEncoding.GetChars]byteCount is negative"); Contract.Assert(chars != null, "[ASCIIEncoding.GetChars]chars is null"); Contract.Assert(charCount >= 0, "[ASCIIEncoding.GetChars]charCount is negative"); // Do it fast way if using ? replacement fallback byte *byteEnd = bytes + byteCount; byte *byteStart = bytes; char *charStart = chars; // Note: ASCII doesn't do best fit, but we have to fallback if they use something > 0x7f // Only need decoder fallback buffer if not using ? fallback. // ASCII doesn't do best fit, so don't have to check for it, find out which decoder fallback we're using DecoderReplacementFallback fallback = null; if (decoder == null) { fallback = this.DecoderFallback as DecoderReplacementFallback; } else { fallback = decoder.Fallback as DecoderReplacementFallback; Contract.Assert(!decoder.m_throwOnOverflow || !decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0, "[ASCIICodePageEncoding.GetChars]Expected empty fallback buffer"); } if (fallback != null && fallback.MaxCharCount == 1) { // Try it the fast way char replacementChar = fallback.DefaultString[0]; // Need byteCount chars, otherwise too small buffer if (charCount < byteCount) { // Need at least 1 output byte, throw if must throw ThrowCharsOverflow(decoder, charCount < 1); // Not throwing, use what we can byteEnd = bytes + charCount; } // Quick loop, just do '?' replacement because we don't have fallbacks for decodings. while (bytes < byteEnd) { byte b = *(bytes++); if (b >= 0x80) { // This is an invalid byte in the ASCII encoding. *(chars++) = replacementChar; } else { *(chars++) = unchecked ((char)b); } } // bytes & chars used are the same if (decoder != null) { decoder.m_bytesUsed = (int)(bytes - byteStart); } return((int)(chars - charStart)); } // Slower way's going to need a fallback buffer DecoderFallbackBuffer fallbackBuffer = null; byte[] byteBuffer = new byte[1]; char * charEnd = chars + charCount; // Not quite so fast loop while (bytes < byteEnd) { // Faster if don't use *bytes++; byte b = *(bytes); bytes++; if (b >= 0x80) { // This is an invalid byte in the ASCII encoding. if (fallbackBuffer == null) { if (decoder == null) { fallbackBuffer = this.DecoderFallback.CreateFallbackBuffer(); } else { fallbackBuffer = decoder.FallbackBuffer; } fallbackBuffer.InternalInitialize(byteEnd - byteCount, charEnd); } // Use fallback buffer byteBuffer[0] = b; // Note that chars won't get updated unless this succeeds if (!fallbackBuffer.InternalFallback(byteBuffer, bytes, ref chars)) { // May or may not throw, but we didn't get this byte Contract.Assert(bytes > byteStart || chars == charStart, "[ASCIIEncoding.GetChars]Expected bytes to have advanced already (fallback case)"); bytes--; // unused byte fallbackBuffer.InternalReset(); // Didn't fall this back ThrowCharsOverflow(decoder, chars == charStart); // throw? break; // don't throw, but stop loop } } else { // Make sure we have buffer space if (chars >= charEnd) { Contract.Assert(bytes > byteStart || chars == charStart, "[ASCIIEncoding.GetChars]Expected bytes to have advanced already (normal case)"); bytes--; // unused byte ThrowCharsOverflow(decoder, chars == charStart); // throw? break; // don't throw, but stop loop } *(chars) = unchecked ((char)b); chars++; } } // Might have had decoder fallback stuff. if (decoder != null) { decoder.m_bytesUsed = (int)(bytes - byteStart); } // Expect Empty fallback buffer for GetChars Contract.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0, "[ASCIIEncoding.GetChars]Expected Empty fallback buffer"); return((int)(chars - charStart)); }
internal unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS decoder) { byte *ptr = bytes + byteCount; byte *ptr2 = bytes; char *ptr3 = chars; DecoderReplacementFallback decoderReplacementFallback; if (decoder == null) { decoderReplacementFallback = (base.DecoderFallback as DecoderReplacementFallback); } else { decoderReplacementFallback = (decoder.Fallback as DecoderReplacementFallback); } if (decoderReplacementFallback != null && decoderReplacementFallback.MaxCharCount == 1) { char c = decoderReplacementFallback.DefaultString[0]; if (charCount < byteCount) { base.ThrowCharsOverflow(decoder, charCount < 1); ptr = bytes + charCount; } while (bytes < ptr) { byte b = *(bytes++); if (b >= 128) { *(chars++) = c; } else { *(chars++) = (char)b; } } if (decoder != null) { decoder.m_bytesUsed = (int)((long)(bytes - ptr2)); } return((int)((long)(chars - ptr3))); } DecoderFallbackBuffer decoderFallbackBuffer = null; byte[] array = new byte[1]; char * ptr4 = chars + charCount; while (bytes < ptr) { byte b2 = *bytes; bytes++; if (b2 >= 128) { if (decoderFallbackBuffer == null) { if (decoder == null) { decoderFallbackBuffer = base.DecoderFallback.CreateFallbackBuffer(); } else { decoderFallbackBuffer = decoder.FallbackBuffer; } decoderFallbackBuffer.InternalInitialize(ptr - byteCount, ptr4); } array[0] = b2; if (!decoderFallbackBuffer.InternalFallback(array, bytes, ref chars)) { bytes--; decoderFallbackBuffer.InternalReset(); base.ThrowCharsOverflow(decoder, chars == ptr3); break; } } else { if (chars >= ptr4) { bytes--; base.ThrowCharsOverflow(decoder, chars == ptr3); break; } *chars = (char)b2; chars++; } } if (decoder != null) { decoder.m_bytesUsed = (int)((long)(bytes - ptr2)); } return((int)((long)(chars - ptr3))); }
internal unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS decoder) { base.CheckMemorySection(); byte *ptr = bytes + byteCount; byte *ptr2 = bytes; char *ptr3 = chars; DecoderReplacementFallback decoderReplacementFallback; bool isMicrosoftBestFitFallback; if (decoder == null) { decoderReplacementFallback = (base.DecoderFallback as DecoderReplacementFallback); isMicrosoftBestFitFallback = base.DecoderFallback.IsMicrosoftBestFitFallback; } else { decoderReplacementFallback = (decoder.Fallback as DecoderReplacementFallback); isMicrosoftBestFitFallback = decoder.Fallback.IsMicrosoftBestFitFallback; } if (isMicrosoftBestFitFallback || (decoderReplacementFallback != null && decoderReplacementFallback.MaxCharCount == 1)) { char c; if (decoderReplacementFallback == null) { c = '?'; } else { c = decoderReplacementFallback.DefaultString[0]; } if (charCount < byteCount) { base.ThrowCharsOverflow(decoder, charCount < 1); ptr = bytes + charCount; } while (bytes < ptr) { char c2; if (isMicrosoftBestFitFallback) { if (this.arrayBytesBestFit == null) { this.ReadBestFitTable(); } c2 = this.arrayBytesBestFit[(int)(*bytes)]; } else { c2 = this.mapBytesToUnicode[*bytes]; } bytes++; if (c2 == '�') { *chars = c; } else { *chars = c2; } chars++; } if (decoder != null) { decoder.m_bytesUsed = (int)((long)(bytes - ptr2)); } return((int)((long)(chars - ptr3))); } DecoderFallbackBuffer decoderFallbackBuffer = null; byte[] array = new byte[1]; char * ptr4 = chars + charCount; while (bytes < ptr) { char c3 = this.mapBytesToUnicode[*bytes]; bytes++; if (c3 == '�') { if (decoderFallbackBuffer == null) { if (decoder == null) { decoderFallbackBuffer = base.DecoderFallback.CreateFallbackBuffer(); } else { decoderFallbackBuffer = decoder.FallbackBuffer; } decoderFallbackBuffer.InternalInitialize(ptr - byteCount, ptr4); } array[0] = *(bytes - 1); if (!decoderFallbackBuffer.InternalFallback(array, bytes, ref chars)) { bytes--; decoderFallbackBuffer.InternalReset(); base.ThrowCharsOverflow(decoder, bytes == ptr2); break; } } else { if (chars >= ptr4) { bytes--; base.ThrowCharsOverflow(decoder, bytes == ptr2); break; } *chars = c3; chars++; } } if (decoder != null) { decoder.m_bytesUsed = (int)((long)(bytes - ptr2)); } return((int)((long)(chars - ptr3))); }
internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder) { Debug.Assert(chars != null, "[UTF32Encoding.GetChars]chars!=null"); Debug.Assert(bytes != null, "[UTF32Encoding.GetChars]bytes!=null"); Debug.Assert(byteCount >= 0, "[UTF32Encoding.GetChars]byteCount >=0"); Debug.Assert(charCount >= 0, "[UTF32Encoding.GetChars]charCount >=0"); UTF32Decoder decoder = (UTF32Decoder)baseDecoder; // None so far! char *charStart = chars; char *charEnd = chars + charCount; byte *byteStart = bytes; byte *byteEnd = bytes + byteCount; // See if there's anything in our decoder (but don't clear it yet) int readCount = 0; uint iChar = 0; // For fallback we may need a fallback buffer DecoderFallbackBuffer fallbackBuffer = null; // See if there's anything in our decoder if (decoder != null) { readCount = decoder.readByteCount; iChar = (uint)decoder.iChar; fallbackBuffer = baseDecoder.FallbackBuffer; // Shouldn't have anything in fallback buffer for GetChars // (don't have to check m_throwOnOverflow for chars) Debug.Assert(fallbackBuffer.Remaining == 0, "[UTF32Encoding.GetChars]Expected empty fallback buffer at start"); } else { fallbackBuffer = this.decoderFallback.CreateFallbackBuffer(); } // Set our internal fallback interesting things. fallbackBuffer.InternalInitialize(bytes, chars + charCount); // Loop through our input, 4 characters at a time! while (bytes < byteEnd) { // Get our next character if (_bigEndian) { // Scoot left and add it to the bottom iChar <<= 8; iChar += *(bytes++); } else { // Scoot right and add it to the top iChar >>= 8; iChar += (uint)(*(bytes++)) << 24; } readCount++; // See if we have all the bytes yet if (readCount < 4) { continue; } // Have the bytes readCount = 0; // See if its valid to encode if (iChar > 0x10FFFF || (iChar >= 0xD800 && iChar <= 0xDFFF)) { // Need to fall back these 4 bytes byte[] fallbackBytes; if (_bigEndian) { fallbackBytes = new byte[] { unchecked ((byte)(iChar >> 24)), unchecked ((byte)(iChar >> 16)), unchecked ((byte)(iChar >> 8)), unchecked ((byte)(iChar)) }; } else { fallbackBytes = new byte[] { unchecked ((byte)(iChar)), unchecked ((byte)(iChar >> 8)), unchecked ((byte)(iChar >> 16)), unchecked ((byte)(iChar >> 24)) }; } // Chars won't be updated unless this works. if (!fallbackBuffer.InternalFallback(fallbackBytes, bytes, ref chars)) { // Couldn't fallback, throw or wait til next time // We either read enough bytes for bytes-=4 to work, or we're // going to throw in ThrowCharsOverflow because chars == charStart Debug.Assert(bytes >= byteStart + 4 || chars == charStart, "[UTF32Encoding.GetChars]Expected to have consumed bytes or throw (bad surrogate)"); bytes -= 4; // get back to where we were iChar = 0; // Remembering nothing fallbackBuffer.InternalReset(); ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output break; // Stop here, didn't throw } // Ignore the illegal character iChar = 0; continue; } // Ok, we have something we can add to our output if (iChar >= 0x10000) { // Surrogates take 2 if (chars >= charEnd - 1) { // Throwing or stopping // We either read enough bytes for bytes-=4 to work, or we're // going to throw in ThrowCharsOverflow because chars == charStart Debug.Assert(bytes >= byteStart + 4 || chars == charStart, "[UTF32Encoding.GetChars]Expected to have consumed bytes or throw (surrogate)"); bytes -= 4; // get back to where we were iChar = 0; // Remembering nothing ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output break; // Stop here, didn't throw } *(chars++) = GetHighSurrogate(iChar); iChar = GetLowSurrogate(iChar); } // Bounds check for normal character else if (chars >= charEnd) { // Throwing or stopping // We either read enough bytes for bytes-=4 to work, or we're // going to throw in ThrowCharsOverflow because chars == charStart Debug.Assert(bytes >= byteStart + 4 || chars == charStart, "[UTF32Encoding.GetChars]Expected to have consumed bytes or throw (normal char)"); bytes -= 4; // get back to where we were iChar = 0; // Remembering nothing ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output break; // Stop here, didn't throw } // Add the rest of the surrogate or our normal character *(chars++) = (char)iChar; // iChar is back to 0 iChar = 0; } // See if we have something left over that has to be decoded if (readCount > 0 && (decoder == null || decoder.MustFlush)) { // Oops, there's something left over with no place to go. byte[] fallbackBytes = new byte[readCount]; int tempCount = readCount; if (_bigEndian) { while (tempCount > 0) { fallbackBytes[--tempCount] = unchecked ((byte)iChar); iChar >>= 8; } } else { while (tempCount > 0) { fallbackBytes[--tempCount] = unchecked ((byte)(iChar >> 24)); iChar <<= 8; } } if (!fallbackBuffer.InternalFallback(fallbackBytes, bytes, ref chars)) { // Couldn't fallback. fallbackBuffer.InternalReset(); ThrowCharsOverflow(decoder, chars == charStart);// Might throw, if no chars output // Stop here, didn't throw, backed up, so still nothing in buffer } else { // Don't clear our decoder unless we could fall it back. // If we caught the if above, then we're a convert() and will catch this next time. readCount = 0; iChar = 0; } } // Remember any left over stuff, clearing buffer as well for MustFlush if (decoder != null) { decoder.iChar = (int)iChar; decoder.readByteCount = readCount; decoder.m_bytesUsed = (int)(bytes - byteStart); } // Shouldn't have anything in fallback buffer for GetChars // (don't have to check m_throwOnOverflow for chars) Debug.Assert(fallbackBuffer.Remaining == 0, "[UTF32Encoding.GetChars]Expected empty fallback buffer at end"); // Return our count return((int)(chars - charStart)); }
internal unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder) { base.CheckMemorySection(); DBCSCodePageEncoding.DBCSDecoder dbcsdecoder = (DBCSCodePageEncoding.DBCSDecoder)baseDecoder; byte *ptr = bytes; byte *ptr2 = bytes + byteCount; char *ptr3 = chars; char *ptr4 = chars + charCount; bool flag = false; DecoderFallbackBuffer decoderFallbackBuffer = null; if (dbcsdecoder != null && dbcsdecoder.bLeftOver > 0) { if (byteCount == 0) { if (!dbcsdecoder.MustFlush) { return(0); } decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(bytes, ptr4); byte[] bytes2 = new byte[] { dbcsdecoder.bLeftOver }; if (!decoderFallbackBuffer.InternalFallback(bytes2, bytes, ref chars)) { base.ThrowCharsOverflow(dbcsdecoder, true); } dbcsdecoder.bLeftOver = 0; return((int)((long)(chars - ptr3))); } else { int num = (int)dbcsdecoder.bLeftOver << 8; num |= (int)(*bytes); bytes++; char c = this.mapBytesToUnicode[num]; if (c == '\0' && num != 0) { decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(ptr2 - byteCount, ptr4); byte[] bytes3 = new byte[] { (byte)(num >> 8), (byte)num }; if (!decoderFallbackBuffer.InternalFallback(bytes3, bytes, ref chars)) { base.ThrowCharsOverflow(dbcsdecoder, true); } } else { if (chars >= ptr4) { base.ThrowCharsOverflow(dbcsdecoder, true); } *(chars++) = c; } } } while (bytes < ptr2) { int num2 = (int)(*bytes); bytes++; char c2 = this.mapBytesToUnicode[num2]; if (c2 == '') { if (bytes < ptr2) { num2 <<= 8; num2 |= (int)(*bytes); bytes++; c2 = this.mapBytesToUnicode[num2]; } else { if (dbcsdecoder != null && !dbcsdecoder.MustFlush) { flag = true; dbcsdecoder.bLeftOver = (byte)num2; break; } c2 = '\0'; } } if (c2 == '\0' && num2 != 0) { if (decoderFallbackBuffer == null) { if (dbcsdecoder == null) { decoderFallbackBuffer = base.DecoderFallback.CreateFallbackBuffer(); } else { decoderFallbackBuffer = dbcsdecoder.FallbackBuffer; } decoderFallbackBuffer.InternalInitialize(ptr2 - byteCount, ptr4); } byte[] array; if (num2 < 256) { array = new byte[] { (byte)num2 }; } else { array = new byte[] { (byte)(num2 >> 8), (byte)num2 }; } if (!decoderFallbackBuffer.InternalFallback(array, bytes, ref chars)) { bytes -= array.Length; decoderFallbackBuffer.InternalReset(); base.ThrowCharsOverflow(dbcsdecoder, bytes == ptr); break; } } else { if (chars >= ptr4) { bytes--; if (num2 >= 256) { bytes--; } base.ThrowCharsOverflow(dbcsdecoder, bytes == ptr); break; } *(chars++) = c2; } } if (dbcsdecoder != null) { if (!flag) { dbcsdecoder.bLeftOver = 0; } dbcsdecoder.m_bytesUsed = (int)((long)(bytes - ptr)); } return((int)((long)(chars - ptr3))); }
internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS decoder) { this.CheckMemorySection(); byte *numPtr1 = bytes + byteCount; byte *numPtr2 = bytes; char *chPtr = chars; DecoderReplacementFallback replacementFallback; bool microsoftBestFitFallback; if (decoder == null) { replacementFallback = this.DecoderFallback as DecoderReplacementFallback; microsoftBestFitFallback = this.DecoderFallback.IsMicrosoftBestFitFallback; } else { replacementFallback = decoder.Fallback as DecoderReplacementFallback; microsoftBestFitFallback = decoder.Fallback.IsMicrosoftBestFitFallback; } if (microsoftBestFitFallback || replacementFallback != null && replacementFallback.MaxCharCount == 1) { char ch1 = replacementFallback != null ? replacementFallback.DefaultString[0] : '?'; if (charCount < byteCount) { this.ThrowCharsOverflow(decoder, charCount < 1); numPtr1 = bytes + charCount; } while (bytes < numPtr1) { char ch2; if (microsoftBestFitFallback) { if (this.arrayBytesBestFit == null) { this.ReadBestFitTable(); } ch2 = this.arrayBytesBestFit[(int)*bytes]; } else { ch2 = this.mapBytesToUnicode[*bytes]; } ++bytes; *chars = (int)ch2 != 65533 ? ch2 : ch1; chars += 2; } if (decoder != null) { decoder.m_bytesUsed = (int)(bytes - numPtr2); } return((int)(chars - chPtr)); } DecoderFallbackBuffer decoderFallbackBuffer = (DecoderFallbackBuffer)null; byte[] bytes1 = new byte[1]; char * charEnd = chars + charCount; while (bytes < numPtr1) { char ch = this.mapBytesToUnicode[*bytes]; ++bytes; if ((int)ch == 65533) { if (decoderFallbackBuffer == null) { decoderFallbackBuffer = decoder != null ? decoder.FallbackBuffer : this.DecoderFallback.CreateFallbackBuffer(); decoderFallbackBuffer.InternalInitialize(numPtr1 - byteCount, charEnd); } bytes1[0] = *(bytes - 1); if (!decoderFallbackBuffer.InternalFallback(bytes1, bytes, ref chars)) { --bytes; decoderFallbackBuffer.InternalReset(); this.ThrowCharsOverflow(decoder, bytes == numPtr2); break; } } else { if (chars >= charEnd) { --bytes; this.ThrowCharsOverflow(decoder, bytes == numPtr2); break; } *chars = ch; chars += 2; } } if (decoder != null) { decoder.m_bytesUsed = (int)(bytes - numPtr2); } return((int)(chars - chPtr)); }
internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS baseDecoder) { this.CheckMemorySection(); DBCSCodePageEncoding.DBCSDecoder dbcsDecoder = (DBCSCodePageEncoding.DBCSDecoder)baseDecoder; byte *numPtr1 = bytes; byte *numPtr2 = bytes + byteCount; char *chPtr = chars; char *charEnd = chars + charCount; bool flag = false; DecoderFallbackBuffer decoderFallbackBuffer = (DecoderFallbackBuffer)null; if (dbcsDecoder != null && (int)dbcsDecoder.bLeftOver > 0) { if (byteCount == 0) { if (!dbcsDecoder.MustFlush) { return(0); } DecoderFallbackBuffer fallbackBuffer = dbcsDecoder.FallbackBuffer; fallbackBuffer.InternalInitialize(bytes, charEnd); byte[] bytes1 = new byte[1] { dbcsDecoder.bLeftOver }; if (!fallbackBuffer.InternalFallback(bytes1, bytes, ref chars)) { this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, true); } dbcsDecoder.bLeftOver = (byte)0; return((int)(chars - chPtr)); } int index = (int)dbcsDecoder.bLeftOver << 8 | (int)*bytes; ++bytes; char ch = this.mapBytesToUnicode[index]; if ((int)ch == 0 && index != 0) { decoderFallbackBuffer = dbcsDecoder.FallbackBuffer; decoderFallbackBuffer.InternalInitialize(numPtr2 - byteCount, charEnd); byte[] bytes1 = new byte[2] { (byte)(index >> 8), (byte)index }; if (!decoderFallbackBuffer.InternalFallback(bytes1, bytes, ref chars)) { this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, true); } } else { if (chars >= charEnd) { this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, true); } *chars++ = ch; } } while (bytes < numPtr2) { int index = (int)*bytes; ++bytes; char ch = this.mapBytesToUnicode[index]; if ((int)ch == 65534) { if (bytes < numPtr2) { index = index << 8 | (int)*bytes; ++bytes; ch = this.mapBytesToUnicode[index]; } else if (dbcsDecoder == null || dbcsDecoder.MustFlush) { ch = char.MinValue; } else { flag = true; dbcsDecoder.bLeftOver = (byte)index; break; } } if ((int)ch == 0 && index != 0) { if (decoderFallbackBuffer == null) { decoderFallbackBuffer = dbcsDecoder != null ? dbcsDecoder.FallbackBuffer : this.DecoderFallback.CreateFallbackBuffer(); decoderFallbackBuffer.InternalInitialize(numPtr2 - byteCount, charEnd); } byte[] bytes1; if (index < 256) { bytes1 = new byte[1] { (byte)index } } ; else { bytes1 = new byte[2] { (byte)(index >> 8), (byte)index } }; if (!decoderFallbackBuffer.InternalFallback(bytes1, bytes, ref chars)) { bytes -= bytes1.Length; decoderFallbackBuffer.InternalReset(); this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, bytes == numPtr1); break; } } else { if (chars >= charEnd) { --bytes; if (index >= 256) { --bytes; } this.ThrowCharsOverflow((DecoderNLS)dbcsDecoder, bytes == numPtr1); break; } *chars++ = ch; } } if (dbcsDecoder != null) { if (!flag) { dbcsDecoder.bLeftOver = (byte)0; } dbcsDecoder.m_bytesUsed = (int)(bytes - numPtr1); } return((int)(chars - chPtr)); }
internal override unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, DecoderNLS decoder) { byte *numPtr1 = bytes + byteCount; byte *numPtr2 = bytes; char *chPtr = chars; DecoderReplacementFallback replacementFallback = decoder != null ? decoder.Fallback as DecoderReplacementFallback : this.DecoderFallback as DecoderReplacementFallback; if (replacementFallback != null && replacementFallback.MaxCharCount == 1) { char ch = replacementFallback.DefaultString[0]; if (charCount < byteCount) { this.ThrowCharsOverflow(decoder, charCount < 1); numPtr1 = bytes + charCount; } while (bytes < numPtr1) { byte num = *bytes++; * chars++ = (int)num < 128 ? (char)num : ch; } if (decoder != null) { decoder.m_bytesUsed = (int)(bytes - numPtr2); } return((int)(chars - chPtr)); } DecoderFallbackBuffer decoderFallbackBuffer = (DecoderFallbackBuffer)null; byte[] bytes1 = new byte[1]; char * charEnd = chars + charCount; while (bytes < numPtr1) { byte num = *bytes; ++bytes; if ((int)num >= 128) { if (decoderFallbackBuffer == null) { decoderFallbackBuffer = decoder != null ? decoder.FallbackBuffer : this.DecoderFallback.CreateFallbackBuffer(); decoderFallbackBuffer.InternalInitialize(numPtr1 - byteCount, charEnd); } bytes1[0] = num; if (!decoderFallbackBuffer.InternalFallback(bytes1, bytes, ref chars)) { --bytes; decoderFallbackBuffer.InternalReset(); this.ThrowCharsOverflow(decoder, chars == chPtr); break; } } else { if (chars >= charEnd) { --bytes; this.ThrowCharsOverflow(decoder, chars == chPtr); break; } *chars = (char)num; chars += 2; } } if (decoder != null) { decoder.m_bytesUsed = (int)(bytes - numPtr2); } return((int)(chars - chPtr)); }