// Token: 0x06000BC9 RID: 3017 RVA: 0x0006AB78 File Offset: 0x00068D78
        internal Iso2022JpDecoder(Iso2022JpEncoding parent)
        {
            this.killSwitch = Iso2022JpEncoding.InternalReadKillSwitch();
            this.parent     = parent;
            switch (this.killSwitch)
            {
            case Iso2022DecodingMode.Default:
                this.defaultDecoder = parent.DefaultEncoding.GetDecoder();
                break;

            case Iso2022DecodingMode.Override:
                this.subDecoders            = DecodeToCp932.GetStandardOrder();
                this.cp932Decoder           = Encoding.GetEncoding(932).GetDecoder();
                this.currentSubDecoder      = -1;
                this.lastChanceDecoderIndex = DecodeToCp932.LastChanceDecoderIndex;
                this.leftovers = null;
                this.escape    = new Escape();
                break;

            case Iso2022DecodingMode.Throw:
                break;

            default:
                throw new InvalidOperationException("Invalid Iso2022DecodingMode!");
            }
            this.sbSummary = new StringBuilder(32);
        }
Exemplo n.º 2
0
 public static DecodeToCp932[] GetStandardOrder()
 {
     DecodeToCp932[] result = new DecodeToCp932[]
     {
         new DecodeUsAsciiToCp932(),
         new DecodeJisX0208_1983ToCp932(),
         new DecodeJisX0201_1976ToCp932(),
         new DecodeLastChanceToCp932()
     };
     DecodeToCp932.LastChanceIndex = 3;
     return(result);
 }
 // Token: 0x06000BCD RID: 3021 RVA: 0x0006AF24 File Offset: 0x00069124
 private void GetNextRun(byte[] bytes, int byteIndex, int byteCount, out int bytesConsumed, out int cp932ByteCount)
 {
     bytesConsumed  = 0;
     cp932ByteCount = 0;
     DecodeToCp932.MapEscape(bytes, byteIndex, byteCount, this.escape);
     if (this.escape.Sequence == EscapeSequence.Incomplete)
     {
         bytesConsumed         += this.escape.BytesInCurrentBuffer;
         this.currentSubDecoder = this.lastChanceDecoderIndex;
         this.sbSummary.Append("|");
         return;
     }
     if (this.currentSubDecoder != -1 && !this.escape.IsValidEscapeSequence)
     {
         int num;
         int num2;
         ValidationResult runLength = this.subDecoders[this.currentSubDecoder].GetRunLength(bytes, byteIndex, byteCount, this.escape, out num, out num2);
         if (runLength == ValidationResult.Valid && num > 0)
         {
             cp932ByteCount = num2;
             bytesConsumed  = num;
             this.sbSummary.AppendFormat("|{0}", bytesConsumed);
             return;
         }
     }
     this.runCount++;
     if (this.escape.IsValidEscapeSequence)
     {
         int i = 0;
         while (i < this.subDecoders.Length)
         {
             if (this.subDecoders[i].IsEscapeSequenceHandled(this.escape))
             {
                 int num;
                 int num2;
                 ValidationResult runLength = this.subDecoders[i].GetRunLength(bytes, byteIndex, byteCount, this.escape, out num, out num2);
                 if (runLength != ValidationResult.Valid)
                 {
                     string message = string.Format("{0}.IsEscapeSequenceCovered and GetRunLength must agree on validity", this.subDecoders[i].GetType().Name);
                     throw new InvalidOperationException(message);
                 }
                 cp932ByteCount         = num2;
                 bytesConsumed          = num;
                 this.currentSubDecoder = i;
                 this.sbSummary.AppendFormat("E{0}{1}", this.escape.Abbreviation, bytesConsumed);
                 return;
             }
             else
             {
                 i++;
             }
         }
     }
     else
     {
         for (int i = 0; i < this.subDecoders.Length; i++)
         {
             int num;
             int num2;
             ValidationResult runLength = this.subDecoders[i].GetRunLength(bytes, byteIndex, byteCount, this.escape, out num, out num2);
             if (runLength == ValidationResult.Valid && (num > 0 || (num < byteCount && bytes[byteIndex + num] == 0)))
             {
                 this.currentSubDecoder = i;
                 cp932ByteCount         = num2;
                 bytesConsumed          = num;
                 this.sbSummary.AppendFormat("{0}{1}", this.subDecoders[i].Abbreviation, bytesConsumed);
                 return;
             }
         }
     }
     throw new InvalidOperationException("What happened to the last-chance decoder?");
 }