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

◆ GetBytes() [2/9]

unsafe override int System.Text.UTF7Encoding.GetBytes ( char * chars,
int charCount,
byte * bytes,
int byteCount,
EncoderNLS baseEncoder )
inlinesealedpackagevirtual

Reimplemented from System.Text.Encoding.

Definition at line 482 of file UTF7Encoding.cs.

483 {
484 Encoder encoder = (Encoder)baseEncoder;
485 int num = 0;
486 int num2 = -1;
487 EncodingByteBuffer encodingByteBuffer = new EncodingByteBuffer(this, encoder, bytes, byteCount, chars, charCount);
488 if (encoder != null)
489 {
490 num = encoder.bits;
491 num2 = encoder.bitCount;
492 while (num2 >= 6)
493 {
494 num2 -= 6;
495 if (!encodingByteBuffer.AddByte(_base64Bytes[(num >> num2) & 0x3F]))
496 {
497 ThrowBytesOverflow(encoder, encodingByteBuffer.Count == 0);
498 }
499 }
500 }
501 while (encodingByteBuffer.MoreData)
502 {
503 char nextChar = encodingByteBuffer.GetNextChar();
504 if (nextChar < '\u0080' && _directEncode[(uint)nextChar])
505 {
506 if (num2 >= 0)
507 {
508 if (num2 > 0)
509 {
510 if (!encodingByteBuffer.AddByte(_base64Bytes[(num << 6 - num2) & 0x3F]))
511 {
512 break;
513 }
514 num2 = 0;
515 }
516 if (!encodingByteBuffer.AddByte(45))
517 {
518 break;
519 }
520 num2 = -1;
521 }
522 if (!encodingByteBuffer.AddByte((byte)nextChar))
523 {
524 break;
525 }
526 continue;
527 }
528 if (num2 < 0 && nextChar == '+')
529 {
530 if (!encodingByteBuffer.AddByte((byte)43, (byte)45))
531 {
532 break;
533 }
534 continue;
535 }
536 if (num2 < 0)
537 {
538 if (!encodingByteBuffer.AddByte(43))
539 {
540 break;
541 }
542 num2 = 0;
543 }
544 num = (num << 16) | nextChar;
545 num2 += 16;
546 while (num2 >= 6)
547 {
548 num2 -= 6;
549 if (!encodingByteBuffer.AddByte(_base64Bytes[(num >> num2) & 0x3F]))
550 {
551 num2 += 6;
552 encodingByteBuffer.GetNextChar();
553 break;
554 }
555 }
556 if (num2 >= 6)
557 {
558 break;
559 }
560 }
561 if (num2 >= 0 && (encoder == null || encoder.MustFlush))
562 {
563 if (num2 > 0 && encodingByteBuffer.AddByte(_base64Bytes[(num << 6 - num2) & 0x3F]))
564 {
565 num2 = 0;
566 }
567 if (encodingByteBuffer.AddByte(45))
568 {
569 num = 0;
570 num2 = -1;
571 }
572 else
573 {
574 encodingByteBuffer.GetNextChar();
575 }
576 }
577 if (bytes != null && encoder != null)
578 {
579 encoder.bits = num;
580 encoder.bitCount = num2;
581 encoder._charsUsed = encodingByteBuffer.CharsUsed;
582 }
583 return encodingByteBuffer.Count;
584 }

References System.Text.UTF7Encoding._base64Bytes, System.Text.UTF7Encoding._directEncode, System.Text.Encoding.EncodingByteBuffer.AddByte(), System.Text.UTF7Encoding.Encoder.bitCount, System.Text.UTF7Encoding.Encoder.bits, System.byteCount, System.bytes, System.charCount, System.chars, System.Text.Encoding.EncodingByteBuffer.CharsUsed, System.Text.Encoding.EncodingByteBuffer.Count, System.Text.Encoding.EncodingByteBuffer.GetNextChar(), System.Text.Encoding.EncodingByteBuffer.MoreData, System.Text.EncoderNLS.MustFlush, and System.Text.Encoding.ThrowBytesOverflow().