internal override unsafe int GetBytes(char *chars, int charCount, byte *bytes, int byteCount, EncoderNLS baseEncoder) { ISO2022Encoder encoder = (ISO2022Encoder)baseEncoder; int num = 0; switch (this.CodePage) { case 0xc42c: case 0xc42d: case 0xc42e: return(this.GetBytesCP5022xJP(chars, charCount, bytes, byteCount, encoder)); case 0xc42f: case 0xc430: return(num); case 0xc431: return(this.GetBytesCP50225KR(chars, charCount, bytes, byteCount, encoder)); case 0xcec8: return(this.GetBytesCP52936(chars, charCount, bytes, byteCount, encoder)); } return(num); }
[System.Security.SecurityCritical] // auto-generated private unsafe int GetBytesCP52936(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { // prepare our helpers Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer( this, encoder, bytes, byteCount, chars, charCount); // Mode ISO2022Modes currentMode = ISO2022Modes.ModeASCII; // Check our encoder if (encoder != null) { char charLeftOver = encoder.charLeftOver; currentMode = encoder.currentMode; // We may have a left over character from last time, try and process it. if (charLeftOver > 0) { Contract.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP52936]leftover character should be high surrogate"); // It has to be a high surrogate, which we don't support, so it has to be a fallback buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { // Get our char char ch = buffer.GetNextChar(); // Get our bytes ushort sChar = mapUnicodeToBytes[ch]; if (sChar == 0 && ch != 0) { // Wasn't a legal byte sequence, its a surrogate or fallback // Throws if recursive (knows because we called InternalGetNextChar) buffer.Fallback(ch); // Done with our char, now process fallback continue; } // Check for halfwidth bytes byte bLeadByte = (byte)(sChar >> 8); byte bTrailByte = (byte)(sChar & 0xff); // If its a double byte, it has to fit in the lead byte 0xa1 - 0xf7, trail byte 0xa1 - 0xfe range // (including the 0x8080 that our codepage or's to the value) if ((bLeadByte != 0 && (bLeadByte < 0xa1 || bLeadByte > 0xf7 || bTrailByte < 0xa1 || bTrailByte > 0xfe)) || (bLeadByte == 0 && bTrailByte > 0x80 && bTrailByte != 0xff)) { // Illegal character, in 936 code page, but not in HZ subset, get fallback for it buffer.Fallback(ch); continue; } // sChar is now either ASCII or has an 0x8080 mask if (bLeadByte != 0) { // Its a double byte mode if (currentMode != ISO2022Modes.ModeHZ) { // Need to add the double byte mode marker if (!buffer.AddByte((byte)'~', (byte)'{', 2)) break; // Stop if no buffer space in convert currentMode = ISO2022Modes.ModeHZ; } // Go ahead and add the 2 bytes if (!buffer.AddByte(unchecked((byte)(bLeadByte & 0x7f)), unchecked((byte)(bTrailByte & 0x7f)))) break; // Stop if no buffer space in convert } else { // Its supposed to be ASCII if (currentMode != ISO2022Modes.ModeASCII) { // Need to add the ASCII mode marker // Will have 1 more byte (or 2 if ~) if (!buffer.AddByte((byte)'~', (byte)'}', bTrailByte == '~' ? 2:1)) break; currentMode = ISO2022Modes.ModeASCII; } // If its a '~' we'll need an extra one if (bTrailByte == '~') { // Need to add the extra ~ if (!buffer.AddByte((byte)'~', 1)) break; } // Need to add the character if (!buffer.AddByte(bTrailByte)) break; } } // Add ASCII shift out if we're at end of decoder if (currentMode != ISO2022Modes.ModeASCII && (encoder == null || encoder.MustFlush)) { // Need to add the ASCII mode marker // Only turn off other mode if this works if (buffer.AddByte((byte)'~',(byte)'}')) currentMode = ISO2022Modes.ModeASCII; else // If not successful, convert will maintain state for next time, also // AddByte will have decremented our char count, however we need it to remain the same buffer.GetNextChar(); } // Need to remember our mode if (encoder != null && bytes != null) { // This is ASCII if we had to flush encoder.currentMode = currentMode; if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = (char)0; } encoder.m_charsUsed = buffer.CharsUsed; } // Return our length return buffer.Count; }
[System.Security.SecurityCritical] // auto-generated private unsafe int GetBytesCP50225KR(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { // prepare our helpers Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer( this, encoder, bytes, byteCount, chars, charCount); // Get our mode ISO2022Modes currentMode = ISO2022Modes.ModeASCII; // Mode ISO2022Modes shiftOutMode = ISO2022Modes.ModeASCII; // ModeKR if already stamped lead bytes // Check our encoder if (encoder != null) { // May have leftover stuff char charLeftOver = encoder.charLeftOver; currentMode = encoder.currentMode; shiftOutMode = encoder.shiftInOutMode; // We may have a l left over character from last time, try and process it. if (charLeftOver > 0) { Contract.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP50225KR]leftover character should be high surrogate"); // It has to be a high surrogate, which we don't support, so it has to be a fallback buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { // Get our data char ch = buffer.GetNextChar(); // Get our bytes ushort iBytes = mapUnicodeToBytes[ch]; // Check for double byte bytes byte bLeadByte = (byte)(iBytes >> 8); byte bTrailByte = (byte)(iBytes & 0xff); if (bLeadByte != 0) { // // It's a double byte character. // // If we haven't done our Korean designator, then do so, if we have any input if (shiftOutMode != ISO2022Modes.ModeKR) { // Add our code page designator sequence if (!buffer.AddByte(ESCAPE, unchecked((byte)'$'), unchecked((byte)')'), unchecked((byte)'C'))) break; // No room during convert. shiftOutMode = ISO2022Modes.ModeKR; } // May have to switch to ModeKR first if (currentMode != ISO2022Modes.ModeKR) { if (!buffer.AddByte(SHIFT_OUT)) break; // No convert room currentMode = ISO2022Modes.ModeKR; } // Add the bytes if (!buffer.AddByte(bLeadByte, bTrailByte)) break; // no convert room continue; } else if (iBytes != 0 || ch == 0) { // Its a single byte character, switch to ASCII if we have to if (currentMode != ISO2022Modes.ModeASCII) { if (!buffer.AddByte(SHIFT_IN)) break; currentMode = ISO2022Modes.ModeASCII; } // Add the ASCII char if (!buffer.AddByte(bTrailByte)) break; continue; } // Its unknown, do fallback, throws if recursive (knows because we called InternalGetNextChar) buffer.Fallback(ch); } // Switch back to ASCII if MustFlush or no encoder if (currentMode != ISO2022Modes.ModeASCII && (encoder == null || encoder.MustFlush)) { // Get back to ASCII to be safe. Only do it if it success. if (buffer.AddByte(SHIFT_IN)) currentMode = ISO2022Modes.ModeASCII; else // If not successful, convert will maintain state for next time, also // AddByte will have decremented our char count, however we need it to remain the same buffer.GetNextChar(); } // Remember our encoder state if (bytes != null && encoder != null) { // If we didn't use the encoder, then there's no chars left over if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = (char)0; } // This is ASCII if we had to flush encoder.currentMode = currentMode; // We don't use shift out mode, but if we've flushed we need to reset it so it doesn't // get output again. if (!encoder.MustFlush || encoder.charLeftOver != (char)0) { // We should be not flushing or converting Contract.Assert(!encoder.MustFlush || !encoder.m_throwOnOverflow, "[ISO2022Encoding.GetBytesCP50225KR]Expected no left over data or not flushing or not converting"); encoder.shiftInOutMode = shiftOutMode; } else encoder.shiftInOutMode = ISO2022Modes.ModeASCII; encoder.m_charsUsed = buffer.CharsUsed; } // Return our length return buffer.Count; }
[System.Security.SecurityCritical] // auto-generated private unsafe int GetBytesCP5022xJP(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { // prepare our helpers Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer( this, encoder, bytes, byteCount, chars, charCount); // Get our mode ISO2022Modes currentMode = ISO2022Modes.ModeASCII; // Mode ISO2022Modes shiftInMode = ISO2022Modes.ModeASCII; // Mode that shift in will go back to (only used by CP 50222) // Check our encoder if (encoder != null) { char charLeftOver = encoder.charLeftOver; currentMode = encoder.currentMode; shiftInMode = encoder.shiftInOutMode; // We may have a left over character from last time, try and process it. if (charLeftOver > 0) { Contract.Assert(Char.IsHighSurrogate(charLeftOver), "[ISO2022Encoding.GetBytesCP5022xJP]leftover character should be high surrogate"); // It has to be a high surrogate, which we don't support, so it has to be a fallback buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { // Get our char char ch = buffer.GetNextChar(); // Get our bytes ushort iBytes = mapUnicodeToBytes[ch]; StartConvert: // Check for halfwidth bytes byte bLeadByte = (byte)(iBytes >> 8); byte bTrailByte = (byte)(iBytes & 0xff); if (bLeadByte == LEADBYTE_HALFWIDTH) { // Its Halfwidth Katakana if (CodePage == 50220) { // CodePage 50220 doesn't use halfwidth Katakana, convert to fullwidth // See if its out of range, fallback if so, throws if recursive fallback if (bTrailByte < 0x21 || bTrailByte >= 0x21 + HalfToFullWidthKanaTable.Length) { buffer.Fallback(ch); continue; } // Get the full width katakana char to use. iBytes = unchecked((ushort)(HalfToFullWidthKanaTable[bTrailByte - 0x21] & 0x7F7F)); // May have to do all sorts of fun stuff for mode, go back to start convert goto StartConvert; } // Can use halfwidth Katakana, make sure we're in right mode // Make sure we're in right mode if (currentMode != ISO2022Modes.ModeHalfwidthKatakana) { // 50222 or 50221, either shift in/out or escape to get to Katakana mode if (CodePage == 50222) { // Shift Out if (!buffer.AddByte(SHIFT_OUT)) break; // convert out of space, stop // Don't change modes until after AddByte in case it fails for convert // We get to shift out to Katakana, make sure we'll go back to the right mode // (This ends up always being ASCII) shiftInMode = currentMode; currentMode = ISO2022Modes.ModeHalfwidthKatakana; } else { // 50221 does halfwidth katakana by escape sequence Contract.Assert(CodePage == 50221, "[ISO2022Encoding.GetBytesCP5022xJP]Expected Code Page 50221"); // Add our escape sequence if (!buffer.AddByte(ESCAPE, unchecked((byte)'('), unchecked((byte)'I'))) break; // convert out of space, stop currentMode = ISO2022Modes.ModeHalfwidthKatakana; } } // We know we're in Katakana mode now, so add it. // Go ahead and add the Katakana byte. Our table tail bytes are 0x80 too big. if (!buffer.AddByte(unchecked((byte)(bTrailByte & 0x7F)))) break; // convert out of space, stop // Done with this one continue; } else if (bLeadByte != 0) { // // It's a double byte character. // // If we're CP 50222 we may have to shift in from Katakana mode first if (CodePage == 50222 && currentMode == ISO2022Modes.ModeHalfwidthKatakana) { // Shift In if (!buffer.AddByte(SHIFT_IN)) break; // convert out of space, stop // Need to shift in from katakana. (Still might not be right, but won't be shifted out anyway) currentMode = shiftInMode; } // Make sure we're in the right mode (JIS 0208 or JIS 0212) // Note: Right now we don't use JIS 0212. Also this table'd be wrong // Its JIS extension 0208 if (currentMode != ISO2022Modes.ModeJIS0208) { // Escape sequence, we can fail after this, mode will be correct for convert if (!buffer.AddByte(ESCAPE, unchecked((byte)'$'), unchecked((byte)'B'))) break; // Convert out of space, stop currentMode = ISO2022Modes.ModeJIS0208; } // Add our double bytes if (!buffer.AddByte(unchecked((byte)(bLeadByte)), unchecked((byte)(bTrailByte)))) break; // Convert out of space, stop continue; } else if (iBytes != 0 || ch == 0) { // Single byte Char // If we're CP 50222 we may have to shift in from Katakana mode first if (CodePage == 50222 && currentMode == ISO2022Modes.ModeHalfwidthKatakana) { // Shift IN if (!buffer.AddByte(SHIFT_IN)) break; // convert ran out of room // Need to shift in from katakana. (Still might not be right, but won't be shifted out anyway) currentMode = shiftInMode; } // Its a single byte character, switch to ASCII if we have to if (currentMode != ISO2022Modes.ModeASCII) { if (!buffer.AddByte(ESCAPE,unchecked((byte)'('), unchecked((byte)'B'))) break; // convert ran out of room currentMode = ISO2022Modes.ModeASCII; } // Add the ASCII char if (!buffer.AddByte(bTrailByte)) break; // convert had no room left continue; } // Its unknown, do fallback, throws if recursive (knows because we called InternalGetNextChar) buffer.Fallback(ch); } // Switch back to ASCII if MustFlush or no encoder if (currentMode != ISO2022Modes.ModeASCII && (encoder == null || encoder.MustFlush)) { // If we're CP 50222 we may have to shift in from Katakana mode first if (CodePage == 50222 && currentMode == ISO2022Modes.ModeHalfwidthKatakana) { // Shift IN, only shift mode if necessary. if (buffer.AddByte(SHIFT_IN)) // Need to shift in from katakana. (Still might not be right, but won't be shifted out anyway) currentMode = shiftInMode; else // If not successful, convert will maintain state for next time, also // AddByte will have decremented our char count, however we need it to remain the same buffer.GetNextChar(); } // switch back to ASCII to finish neatly if (currentMode != ISO2022Modes.ModeASCII && (CodePage != 50222 || currentMode != ISO2022Modes.ModeHalfwidthKatakana)) { // only shift if it was successful if (buffer.AddByte(ESCAPE, unchecked((byte)'('), unchecked((byte)'B'))) currentMode = ISO2022Modes.ModeASCII; else // If not successful, convert will maintain state for next time, also // AddByte will have decremented our char count, however we need it to remain the same buffer.GetNextChar(); } } // Remember our encoder state if (bytes != null && encoder != null) { // This is ASCII if we had to flush encoder.currentMode = currentMode; encoder.shiftInOutMode = shiftInMode; if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = (char)0; } encoder.m_charsUsed = buffer.CharsUsed; } // Return our length return buffer.Count; }
private unsafe int GetBytesCP52936(char *chars, int charCount, byte *bytes, int byteCount, ISO2022Encoder encoder) { Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount); ISO2022Modes modeASCII = ISO2022Modes.ModeASCII; if (encoder != null) { char charLeftOver = encoder.charLeftOver; modeASCII = encoder.currentMode; if (charLeftOver > '\0') { buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { char nextChar = buffer.GetNextChar(); ushort num = base.mapUnicodeToBytes[nextChar]; if ((num == 0) && (nextChar != '\0')) { buffer.Fallback(nextChar); } else { byte num2 = (byte)(num >> 8); byte num3 = (byte)(num & 0xff); if (((num2 != 0) && (((num2 < 0xa1) || (num2 > 0xf7)) || ((num3 < 0xa1) || (num3 > 0xfe)))) || (((num2 == 0) && (num3 > 0x80)) && (num3 != 0xff))) { buffer.Fallback(nextChar); continue; } if (num2 != 0) { if (modeASCII != ISO2022Modes.ModeHZ) { if (!buffer.AddByte(0x7e, 0x7b, 2)) { break; } modeASCII = ISO2022Modes.ModeHZ; } if (buffer.AddByte((byte)(num2 & 0x7f), (byte)(num3 & 0x7f))) { continue; } break; } if (modeASCII != ISO2022Modes.ModeASCII) { if (!buffer.AddByte(0x7e, 0x7d, (num3 == 0x7e) ? 2 : 1)) { break; } modeASCII = ISO2022Modes.ModeASCII; } if (((num3 == 0x7e) && !buffer.AddByte(0x7e, 1)) || !buffer.AddByte(num3)) { break; } } } if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush)) { if (buffer.AddByte(0x7e, (byte)0x7d)) { modeASCII = ISO2022Modes.ModeASCII; } else { buffer.GetNextChar(); } } if ((encoder != null) && (bytes != null)) { encoder.currentMode = modeASCII; if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = '\0'; } encoder.m_charsUsed = buffer.CharsUsed; } return(buffer.Count); }
private unsafe int GetBytesCP5022xJP(char *chars, int charCount, byte *bytes, int byteCount, ISO2022Encoder encoder) { Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount); ISO2022Modes modeASCII = ISO2022Modes.ModeASCII; ISO2022Modes shiftInOutMode = ISO2022Modes.ModeASCII; if (encoder != null) { char charLeftOver = encoder.charLeftOver; modeASCII = encoder.currentMode; shiftInOutMode = encoder.shiftInOutMode; if (charLeftOver > '\0') { buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { byte num2; byte num3; char nextChar = buffer.GetNextChar(); ushort num = base.mapUnicodeToBytes[nextChar]; while (true) { num2 = (byte)(num >> 8); num3 = (byte)(num & 0xff); if (num2 != 0x10) { goto Label_010A; } if (this.CodePage != 0xc42c) { break; } if ((num3 < 0x21) || (num3 >= (0x21 + HalfToFullWidthKanaTable.Length))) { buffer.Fallback(nextChar); continue; } num = (ushort)(HalfToFullWidthKanaTable[num3 - 0x21] & 0x7f7f); } if (modeASCII != ISO2022Modes.ModeHalfwidthKatakana) { if (this.CodePage == 0xc42e) { if (!buffer.AddByte(14)) { break; } shiftInOutMode = modeASCII; modeASCII = ISO2022Modes.ModeHalfwidthKatakana; } else { if (!buffer.AddByte(0x1b, 40, (byte)0x49)) { break; } modeASCII = ISO2022Modes.ModeHalfwidthKatakana; } } if (buffer.AddByte((byte)(num3 & 0x7f))) { continue; } break; Label_010A: if (num2 != 0) { if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana)) { if (!buffer.AddByte(15)) { break; } modeASCII = shiftInOutMode; } if (modeASCII != ISO2022Modes.ModeJIS0208) { if (!buffer.AddByte(0x1b, 0x24, (byte)0x42)) { break; } modeASCII = ISO2022Modes.ModeJIS0208; } if (buffer.AddByte(num2, num3)) { continue; } break; } if ((num != 0) || (nextChar == '\0')) { if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana)) { if (!buffer.AddByte(15)) { break; } modeASCII = shiftInOutMode; } if (modeASCII != ISO2022Modes.ModeASCII) { if (!buffer.AddByte(0x1b, 40, (byte)0x42)) { break; } modeASCII = ISO2022Modes.ModeASCII; } if (buffer.AddByte(num3)) { continue; } break; } buffer.Fallback(nextChar); } if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush)) { if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana)) { if (buffer.AddByte(15)) { modeASCII = shiftInOutMode; } else { buffer.GetNextChar(); } } if ((modeASCII != ISO2022Modes.ModeASCII) && ((this.CodePage != 0xc42e) || (modeASCII != ISO2022Modes.ModeHalfwidthKatakana))) { if (buffer.AddByte(0x1b, 40, (byte)0x42)) { modeASCII = ISO2022Modes.ModeASCII; } else { buffer.GetNextChar(); } } } if ((bytes != null) && (encoder != null)) { encoder.currentMode = modeASCII; encoder.shiftInOutMode = shiftInOutMode; if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = '\0'; } encoder.m_charsUsed = buffer.CharsUsed; } return(buffer.Count); }
private unsafe int GetBytesCP50225KR(char *chars, int charCount, byte *bytes, int byteCount, ISO2022Encoder encoder) { Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount); ISO2022Modes modeASCII = ISO2022Modes.ModeASCII; ISO2022Modes shiftInOutMode = ISO2022Modes.ModeASCII; if (encoder != null) { char charLeftOver = encoder.charLeftOver; modeASCII = encoder.currentMode; shiftInOutMode = encoder.shiftInOutMode; if (charLeftOver > '\0') { buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { char nextChar = buffer.GetNextChar(); ushort num = base.mapUnicodeToBytes[nextChar]; byte num2 = (byte)(num >> 8); byte num3 = (byte)(num & 0xff); if (num2 != 0) { if (shiftInOutMode != ISO2022Modes.ModeKR) { if (!buffer.AddByte(0x1b, 0x24, 0x29, (byte)0x43)) { break; } shiftInOutMode = ISO2022Modes.ModeKR; } if (modeASCII != ISO2022Modes.ModeKR) { if (!buffer.AddByte(14)) { break; } modeASCII = ISO2022Modes.ModeKR; } if (buffer.AddByte(num2, num3)) { continue; } break; } if ((num != 0) || (nextChar == '\0')) { if (modeASCII != ISO2022Modes.ModeASCII) { if (!buffer.AddByte(15)) { break; } modeASCII = ISO2022Modes.ModeASCII; } if (buffer.AddByte(num3)) { continue; } break; } buffer.Fallback(nextChar); } if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush)) { if (buffer.AddByte(15)) { modeASCII = ISO2022Modes.ModeASCII; } else { buffer.GetNextChar(); } } if ((bytes != null) && (encoder != null)) { if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = '\0'; } encoder.currentMode = modeASCII; if (!encoder.MustFlush || (encoder.charLeftOver != '\0')) { encoder.shiftInOutMode = shiftInOutMode; } else { encoder.shiftInOutMode = ISO2022Modes.ModeASCII; } encoder.m_charsUsed = buffer.CharsUsed; } return(buffer.Count); }
private unsafe int GetBytesCP52936(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount); ISO2022Modes modeASCII = ISO2022Modes.ModeASCII; if (encoder != null) { char charLeftOver = encoder.charLeftOver; modeASCII = encoder.currentMode; if (charLeftOver > '\0') { buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { char nextChar = buffer.GetNextChar(); ushort num = base.mapUnicodeToBytes[nextChar]; if ((num == 0) && (nextChar != '\0')) { buffer.Fallback(nextChar); } else { byte num2 = (byte) (num >> 8); byte num3 = (byte) (num & 0xff); if (((num2 != 0) && (((num2 < 0xa1) || (num2 > 0xf7)) || ((num3 < 0xa1) || (num3 > 0xfe)))) || (((num2 == 0) && (num3 > 0x80)) && (num3 != 0xff))) { buffer.Fallback(nextChar); continue; } if (num2 != 0) { if (modeASCII != ISO2022Modes.ModeHZ) { if (!buffer.AddByte(0x7e, 0x7b, 2)) { break; } modeASCII = ISO2022Modes.ModeHZ; } if (buffer.AddByte((byte) (num2 & 0x7f), (byte) (num3 & 0x7f))) { continue; } break; } if (modeASCII != ISO2022Modes.ModeASCII) { if (!buffer.AddByte(0x7e, 0x7d, (num3 == 0x7e) ? 2 : 1)) { break; } modeASCII = ISO2022Modes.ModeASCII; } if (((num3 == 0x7e) && !buffer.AddByte(0x7e, 1)) || !buffer.AddByte(num3)) { break; } } } if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush)) { if (buffer.AddByte(0x7e, (byte) 0x7d)) { modeASCII = ISO2022Modes.ModeASCII; } else { buffer.GetNextChar(); } } if ((encoder != null) && (bytes != null)) { encoder.currentMode = modeASCII; if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = '\0'; } encoder.m_charsUsed = buffer.CharsUsed; } return buffer.Count; }
private unsafe int GetBytesCP5022xJP(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount); ISO2022Modes modeASCII = ISO2022Modes.ModeASCII; ISO2022Modes shiftInOutMode = ISO2022Modes.ModeASCII; if (encoder != null) { char charLeftOver = encoder.charLeftOver; modeASCII = encoder.currentMode; shiftInOutMode = encoder.shiftInOutMode; if (charLeftOver > '\0') { buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { byte num2; byte num3; char nextChar = buffer.GetNextChar(); ushort num = base.mapUnicodeToBytes[nextChar]; while (true) { num2 = (byte) (num >> 8); num3 = (byte) (num & 0xff); if (num2 != 0x10) { goto Label_010A; } if (this.CodePage != 0xc42c) { break; } if ((num3 < 0x21) || (num3 >= (0x21 + HalfToFullWidthKanaTable.Length))) { buffer.Fallback(nextChar); continue; } num = (ushort) (HalfToFullWidthKanaTable[num3 - 0x21] & 0x7f7f); } if (modeASCII != ISO2022Modes.ModeHalfwidthKatakana) { if (this.CodePage == 0xc42e) { if (!buffer.AddByte(14)) { break; } shiftInOutMode = modeASCII; modeASCII = ISO2022Modes.ModeHalfwidthKatakana; } else { if (!buffer.AddByte(0x1b, 40, (byte) 0x49)) { break; } modeASCII = ISO2022Modes.ModeHalfwidthKatakana; } } if (buffer.AddByte((byte) (num3 & 0x7f))) { continue; } break; Label_010A: if (num2 != 0) { if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana)) { if (!buffer.AddByte(15)) { break; } modeASCII = shiftInOutMode; } if (modeASCII != ISO2022Modes.ModeJIS0208) { if (!buffer.AddByte(0x1b, 0x24, (byte) 0x42)) { break; } modeASCII = ISO2022Modes.ModeJIS0208; } if (buffer.AddByte(num2, num3)) { continue; } break; } if ((num != 0) || (nextChar == '\0')) { if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana)) { if (!buffer.AddByte(15)) { break; } modeASCII = shiftInOutMode; } if (modeASCII != ISO2022Modes.ModeASCII) { if (!buffer.AddByte(0x1b, 40, (byte) 0x42)) { break; } modeASCII = ISO2022Modes.ModeASCII; } if (buffer.AddByte(num3)) { continue; } break; } buffer.Fallback(nextChar); } if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush)) { if ((this.CodePage == 0xc42e) && (modeASCII == ISO2022Modes.ModeHalfwidthKatakana)) { if (buffer.AddByte(15)) { modeASCII = shiftInOutMode; } else { buffer.GetNextChar(); } } if ((modeASCII != ISO2022Modes.ModeASCII) && ((this.CodePage != 0xc42e) || (modeASCII != ISO2022Modes.ModeHalfwidthKatakana))) { if (buffer.AddByte(0x1b, 40, (byte) 0x42)) { modeASCII = ISO2022Modes.ModeASCII; } else { buffer.GetNextChar(); } } } if ((bytes != null) && (encoder != null)) { encoder.currentMode = modeASCII; encoder.shiftInOutMode = shiftInOutMode; if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = '\0'; } encoder.m_charsUsed = buffer.CharsUsed; } return buffer.Count; }
private unsafe int GetBytesCP50225KR(char* chars, int charCount, byte* bytes, int byteCount, ISO2022Encoder encoder) { Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount); ISO2022Modes modeASCII = ISO2022Modes.ModeASCII; ISO2022Modes shiftInOutMode = ISO2022Modes.ModeASCII; if (encoder != null) { char charLeftOver = encoder.charLeftOver; modeASCII = encoder.currentMode; shiftInOutMode = encoder.shiftInOutMode; if (charLeftOver > '\0') { buffer.Fallback(charLeftOver); } } while (buffer.MoreData) { char nextChar = buffer.GetNextChar(); ushort num = base.mapUnicodeToBytes[nextChar]; byte num2 = (byte) (num >> 8); byte num3 = (byte) (num & 0xff); if (num2 != 0) { if (shiftInOutMode != ISO2022Modes.ModeKR) { if (!buffer.AddByte(0x1b, 0x24, 0x29, (byte) 0x43)) { break; } shiftInOutMode = ISO2022Modes.ModeKR; } if (modeASCII != ISO2022Modes.ModeKR) { if (!buffer.AddByte(14)) { break; } modeASCII = ISO2022Modes.ModeKR; } if (buffer.AddByte(num2, num3)) { continue; } break; } if ((num != 0) || (nextChar == '\0')) { if (modeASCII != ISO2022Modes.ModeASCII) { if (!buffer.AddByte(15)) { break; } modeASCII = ISO2022Modes.ModeASCII; } if (buffer.AddByte(num3)) { continue; } break; } buffer.Fallback(nextChar); } if ((modeASCII != ISO2022Modes.ModeASCII) && ((encoder == null) || encoder.MustFlush)) { if (buffer.AddByte(15)) { modeASCII = ISO2022Modes.ModeASCII; } else { buffer.GetNextChar(); } } if ((bytes != null) && (encoder != null)) { if (!buffer.fallbackBuffer.bUsedEncoder) { encoder.charLeftOver = '\0'; } encoder.currentMode = modeASCII; if (!encoder.MustFlush || (encoder.charLeftOver != '\0')) { encoder.shiftInOutMode = shiftInOutMode; } else { encoder.shiftInOutMode = ISO2022Modes.ModeASCII; } encoder.m_charsUsed = buffer.CharsUsed; } return buffer.Count; }