Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetBytesCP52936()

unsafe int System.Text.ISO2022Encoding.GetBytesCP52936 ( char * chars,
int charCount,
byte * bytes,
int byteCount,
ISO2022Encoder encoder )
inlineprivate

Definition at line 533 of file ISO2022Encoding.cs.

534 {
535 EncodingByteBuffer encodingByteBuffer = new EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount);
536 ISO2022Modes iSO2022Modes = ISO2022Modes.ModeASCII;
537 if (encoder != null)
538 {
539 char charLeftOver = encoder.charLeftOver;
540 iSO2022Modes = encoder.currentMode;
541 if (charLeftOver > '\0')
542 {
543 encodingByteBuffer.Fallback(charLeftOver);
544 }
545 }
546 while (encodingByteBuffer.MoreData)
547 {
548 char nextChar = encodingByteBuffer.GetNextChar();
549 ushort num = mapUnicodeToBytes[(int)nextChar];
550 if (num == 0 && nextChar != 0)
551 {
552 encodingByteBuffer.Fallback(nextChar);
553 continue;
554 }
555 byte b = (byte)(num >> 8);
556 byte b2 = (byte)(num & 0xFFu);
557 if ((b != 0 && (b < 161 || b > 247 || b2 < 161 || b2 > 254)) || (b == 0 && b2 > 128 && b2 != byte.MaxValue))
558 {
559 encodingByteBuffer.Fallback(nextChar);
560 continue;
561 }
562 if (b != 0)
563 {
564 if (iSO2022Modes != ISO2022Modes.ModeHZ)
565 {
566 if (!encodingByteBuffer.AddByte(126, 123, 2))
567 {
568 break;
569 }
570 iSO2022Modes = ISO2022Modes.ModeHZ;
571 }
572 if (encodingByteBuffer.AddByte((byte)(b & 0x7Fu), (byte)(b2 & 0x7Fu)))
573 {
574 continue;
575 }
576 break;
577 }
578 if (iSO2022Modes != ISO2022Modes.ModeASCII)
579 {
580 if (!encodingByteBuffer.AddByte(126, 125, (b2 != 126) ? 1 : 2))
581 {
582 break;
583 }
584 iSO2022Modes = ISO2022Modes.ModeASCII;
585 }
586 if ((b2 == 126 && !encodingByteBuffer.AddByte(126, 1)) || !encodingByteBuffer.AddByte(b2))
587 {
588 break;
589 }
590 }
591 if (iSO2022Modes != ISO2022Modes.ModeASCII && (encoder == null || encoder.MustFlush))
592 {
593 if (encodingByteBuffer.AddByte((byte)126, (byte)125))
594 {
595 iSO2022Modes = ISO2022Modes.ModeASCII;
596 }
597 else
598 {
599 encodingByteBuffer.GetNextChar();
600 }
601 }
602 if (encoder != null && bytes != null)
603 {
604 encoder.currentMode = iSO2022Modes;
605 if (!encodingByteBuffer.fallbackBufferHelper.bUsedEncoder)
606 {
607 encoder.charLeftOver = '\0';
608 }
609 encoder.m_charsUsed = encodingByteBuffer.CharsUsed;
610 }
611 return encodingByteBuffer.Count;
612 }

References System.Text.Encoding.EncodingByteBuffer.AddByte(), System.byteCount, System.bytes, System.charCount, System.Text.EncoderNLS.charLeftOver, System.chars, System.Text.Encoding.EncodingByteBuffer.CharsUsed, System.Text.Encoding.EncodingByteBuffer.Count, System.Text.ISO2022Encoding.ISO2022Encoder.currentMode, System.Text.Encoding.EncodingByteBuffer.GetNextChar(), System.Text.DBCSCodePageEncoding.mapUnicodeToBytes, System.Text.Encoding.EncodingByteBuffer.MoreData, and System.Text.EncoderNLS.MustFlush.

Referenced by System.Text.ISO2022Encoding.GetBytes().