Beispiel #1
0
 public Escape(Escape from)
 {
     this.Sequence             = from.Sequence;
     this.State                = from.State;
     this.BytesInCurrentBuffer = from.BytesInCurrentBuffer;
     this.TotalBytes           = from.TotalBytes;
     this.ErrorMessage         = from.ErrorMessage;
 }
        public static void MapEscape(byte[] dataIn, int offsetIn, int lengthIn, Escape escape)
        {
            int         num   = 0;
            EscapeState state = escape.State;
            int         num2  = offsetIn;

            while (lengthIn > 0)
            {
                byte           b = dataIn[offsetIn];
                EscapeSequence sequence;
                switch (escape.State)
                {
                case EscapeState.Begin:
                    if (b == 27)
                    {
                        escape.State = EscapeState.Esc_1;
                    }
                    else
                    {
                        if (b == 14)
                        {
                            sequence = EscapeSequence.ShiftOut;
                            goto IL_33B;
                        }
                        if (b == 15)
                        {
                            sequence = EscapeSequence.ShiftIn;
                            goto IL_33B;
                        }
                        escape.BytesInCurrentBuffer = 0;
                        escape.TotalBytes           = 0;
                        escape.Sequence             = EscapeSequence.None;
                        return;
                    }
                    break;

                case EscapeState.Esc_1:
                    if (b == 36)
                    {
                        escape.State = EscapeState.Esc_Dollar_2;
                    }
                    else if (b == 40)
                    {
                        escape.State = EscapeState.Esc_OpenParen_2;
                    }
                    else
                    {
                        if (b == 72)
                        {
                            sequence = EscapeSequence.NECKanjiIn;
                            goto IL_33B;
                        }
                        if (b == 75)
                        {
                            sequence = EscapeSequence.JisX0208_Nec;
                            goto IL_33B;
                        }
                        if (b == 38)
                        {
                            escape.State = EscapeState.Esc_Ampersand_2;
                        }
                        else
                        {
                            if (b == 27)
                            {
                                goto IL_2C6;
                            }
                            if (b == 14 || b == 15)
                            {
                                goto IL_2CF;
                            }
                            if (b == 0)
                            {
                                goto IL_366;
                            }
                            goto IL_366;
                        }
                    }
                    break;

                case EscapeState.Esc_Dollar_2:
                    if (b == 64)
                    {
                        sequence = EscapeSequence.JisX0208_1983;
                        goto IL_33B;
                    }
                    if (b == 65)
                    {
                        sequence = EscapeSequence.Gb2312_1980;
                        goto IL_33B;
                    }
                    if (b == 66)
                    {
                        sequence = EscapeSequence.JisX0208_1978;
                        goto IL_33B;
                    }
                    if (b == 40)
                    {
                        escape.State = EscapeState.Esc_Dollar_OpenParen_3;
                    }
                    else if (b == 41)
                    {
                        escape.State = EscapeState.Esc_Dollar_CloseParen_3;
                    }
                    else
                    {
                        if (b == 27)
                        {
                            goto IL_2C6;
                        }
                        if (b == 14)
                        {
                            goto IL_2CF;
                        }
                        if (b == 15)
                        {
                            goto IL_2CF;
                        }
                        goto IL_366;
                    }
                    break;

                case EscapeState.Esc_OpenParen_2:
                    if (b == 73)
                    {
                        sequence = EscapeSequence.JisX0201K_1976;
                        goto IL_33B;
                    }
                    if (b == 74)
                    {
                        sequence = EscapeSequence.JisX0201_1976;
                        goto IL_33B;
                    }
                    if (b == 68)
                    {
                        sequence = EscapeSequence.JisX0212_1990;
                        goto IL_33B;
                    }
                    if (b == 66)
                    {
                        sequence = EscapeSequence.Iso646Irv;
                        goto IL_33B;
                    }
                    if (b == 27)
                    {
                        goto IL_2C6;
                    }
                    if (b == 14)
                    {
                        goto IL_2CF;
                    }
                    if (b == 15)
                    {
                        goto IL_2CF;
                    }
                    goto IL_366;

                case EscapeState.Esc_Ampersand_2:
                    if (b == 64)
                    {
                        escape.State = EscapeState.Esc_Ampersand_At_3;
                    }
                    else
                    {
                        if (b == 27)
                        {
                            goto IL_2C6;
                        }
                        if (b == 14)
                        {
                            goto IL_2CF;
                        }
                        if (b == 15)
                        {
                            goto IL_2CF;
                        }
                        goto IL_366;
                    }
                    break;

                case EscapeState.Esc_K_2:
                    goto IL_2F9;

                case EscapeState.Esc_Dollar_OpenParen_3:
                    if (b == 71)
                    {
                        sequence = EscapeSequence.Cns11643_1992_1;
                        goto IL_33B;
                    }
                    if (b == 67)
                    {
                        sequence = EscapeSequence.Kcs5601_1987;
                        goto IL_33B;
                    }
                    if (b == 72)
                    {
                        sequence = EscapeSequence.Cns11643_1992_1;
                        goto IL_33B;
                    }
                    if (b == 81)
                    {
                        sequence = EscapeSequence.Unknown_1;
                        goto IL_33B;
                    }
                    if (b == 27)
                    {
                        goto IL_2C6;
                    }
                    if (b == 14)
                    {
                        goto IL_2CF;
                    }
                    if (b == 15)
                    {
                        goto IL_2CF;
                    }
                    goto IL_366;

                case EscapeState.Esc_Dollar_CloseParen_3:
                    if (b == 67)
                    {
                        sequence = EscapeSequence.EucKsc;
                        goto IL_33B;
                    }
                    if (b == 27)
                    {
                        goto IL_2C6;
                    }
                    if (b == 14)
                    {
                        goto IL_2CF;
                    }
                    if (b == 15)
                    {
                        goto IL_2CF;
                    }
                    goto IL_366;

                case EscapeState.Esc_Ampersand_At_3:
                    if (b == 27)
                    {
                        escape.State = EscapeState.Esc_Ampersand_At_Esc_4;
                    }
                    else
                    {
                        if (b == 14)
                        {
                            goto IL_2CF;
                        }
                        if (b == 15)
                        {
                            goto IL_2CF;
                        }
                        goto IL_366;
                    }
                    break;

                case EscapeState.Esc_Ampersand_At_Esc_4:
                    if (b == 36)
                    {
                        escape.State = EscapeState.Esc_Ampersand_At_Esc_Dollar_5;
                    }
                    else
                    {
                        if (b == 27)
                        {
                            goto IL_2C6;
                        }
                        if (b == 14)
                        {
                            goto IL_2CF;
                        }
                        if (b == 15)
                        {
                            goto IL_2CF;
                        }
                        goto IL_366;
                    }
                    break;

                case EscapeState.Esc_Ampersand_At_Esc_Dollar_5:
                    if (b == 66)
                    {
                        sequence = EscapeSequence.JisX0208_1990;
                        goto IL_33B;
                    }
                    if (b == 27)
                    {
                        goto IL_2C6;
                    }
                    if (b == 14)
                    {
                        goto IL_2CF;
                    }
                    if (b == 15)
                    {
                        goto IL_2CF;
                    }
                    goto IL_366;

                case EscapeState.Esc_Esc_Reset:
                    goto IL_2C6;

                case EscapeState.Esc_SISO_Reset:
                    goto IL_2CF;

                default:
                    goto IL_2F9;
                }
IL_304:
                lengthIn--;
                offsetIn++;
                num++;
                continue;
IL_2C6:
                escape.State = EscapeState.Esc_1;
                goto IL_304;
IL_2CF:
                if (b == 14)
                {
                    sequence = EscapeSequence.ShiftOut;
                    goto IL_33B;
                }
                if (b == 15)
                {
                    sequence = EscapeSequence.ShiftIn;
                    goto IL_33B;
                }
                throw new InvalidOperationException(string.Format("MapEscape: at Esc_SISO_Reset with {0}", (int)b));
IL_2F9:
                throw new InvalidOperationException("MapEscape: unrecognized state!");
IL_33B:
                escape.BytesInCurrentBuffer = num + 1;
                escape.TotalBytes          += escape.BytesInCurrentBuffer;
                escape.State    = EscapeState.Begin;
                escape.Sequence = sequence;
                return;

IL_366:
                string text = string.Empty;
                while (num2 <= offsetIn && num2 < offsetIn + lengthIn)
                {
                    text += dataIn[num2++].ToString("X2");
                }
                string.Format("Unrecognized escape sequence {0}, initial state {1}, current state {2}", text, state.ToString(), escape.State.ToString());
                escape.State                = EscapeState.Begin;
                escape.Sequence             = EscapeSequence.NotRecognized;
                escape.BytesInCurrentBuffer = num;
                escape.TotalBytes          += num;
                return;
            }
            escape.BytesInCurrentBuffer = num;
            escape.TotalBytes          += escape.BytesInCurrentBuffer;
            escape.Sequence             = EscapeSequence.Incomplete;
        }
 public abstract void ConvertToCp932(byte[] dataIn, int offsetIn, int lengthIn, byte[] dataOut, int offsetOut, int lengthOut, bool flush, Escape escape, out int usedIn, out int usedOut, out bool complete);
 // Token: 0x06000B91 RID: 2961 RVA: 0x00069751 File Offset: 0x00067951
 public override bool IsEscapeSequenceHandled(Escape escape)
 {
     return(escape.Sequence == EscapeSequence.JisX0208_1978 || escape.Sequence == EscapeSequence.JisX0208_1983 || escape.Sequence == EscapeSequence.JisX0208_1990);
 }
        // Token: 0x06000B93 RID: 2963 RVA: 0x00069A34 File Offset: 0x00067C34
        public override void ConvertToCp932(byte[] dataIn, int offsetIn, int lengthIn, byte[] dataOut, int offsetOut, int lengthOut, bool flush, Escape escape, out int usedIn, out int usedOut, out bool complete)
        {
            usedIn   = 0;
            usedOut  = 0;
            complete = false;
            bool flag  = false;
            int  i     = offsetIn;
            int  num   = offsetOut;
            int  num2  = 0;
            int  num3  = 0;
            int  limit = this.CalculateLoopCountLimit(lengthIn);

            if (escape.IsValidEscapeSequence)
            {
                if (!this.IsEscapeSequenceHandled(escape))
                {
                    throw new InvalidOperationException(string.Format("unhandled escape sequence: {0}", escape.Sequence));
                }
                i                += escape.BytesInCurrentBuffer;
                this.isKana       = false;
                this.leftoverByte = 0;
            }
            while (i < offsetIn + lengthIn)
            {
                this.CheckLoopCount(ref num3, limit);
                uint num4;
                uint num5;
                int  num6;
                if (this.leftoverByte != 0)
                {
                    if (i != offsetIn)
                    {
                        string message = string.Format("DecodeJisX0208_1983ToCp932.ConvertToCp932: leftover byte processed at offset {0}, should have been {1}", i, offsetIn);
                        throw new InvalidOperationException(message);
                    }
                    num4 = (uint)this.leftoverByte;
                    num5 = (uint)dataIn[i];
                    num6 = 1;
                    this.leftoverByte = 0;
                }
                else if (i + 2 <= offsetIn + lengthIn)
                {
                    num4 = (uint)dataIn[i];
                    num5 = (uint)dataIn[i + 1];
                    num6 = 2;
                }
                else
                {
                    num4 = (uint)dataIn[i];
                    if (num4 == 27U || (!this.runBeganWithEscape && (num4 == 14U || num4 == 15U)) || num4 == 0U)
                    {
                        flag = true;
                        break;
                    }
                    if (this.isKana && num4 != 14U && num4 != 15U)
                    {
                        dataOut[num++] = this.DecodeKana(num4);
                        num2++;
                        i++;
                        break;
                    }
                    break;
                }
                if (num4 == 27U)
                {
                    this.runBeganWithEscape = false;
                    flag = true;
                    break;
                }
                if (num4 == 0U)
                {
                    flag = true;
                    break;
                }
                if (num5 == 27U)
                {
                    this.runBeganWithEscape = false;
                    flag = true;
                    i++;
                    if (!this.isKana || num4 == 14U)
                    {
                        break;
                    }
                    if (num4 == 15U)
                    {
                        this.isKana = false;
                        break;
                    }
                    dataOut[num++] = this.DecodeKana(num4);
                    num2++;
                    break;
                }
                else if (num5 == 0U)
                {
                    flag = true;
                    i++;
                    if (!this.isKana || num4 == 14U)
                    {
                        break;
                    }
                    if (num4 == 15U)
                    {
                        this.isKana = false;
                        break;
                    }
                    dataOut[num++] = this.DecodeKana(num4);
                    num2++;
                    break;
                }
                else
                {
                    if (!this.runBeganWithEscape)
                    {
                        if (num4 == 14U || num4 == 15U || num5 == 14U || num5 == 15U)
                        {
                            flag = true;
                            break;
                        }
                    }
                    else if (num4 == 14U)
                    {
                        this.isKana = true;
                        i          += num6;
                        switch (num5)
                        {
                        case 14U:
                            continue;

                        case 15U:
                            this.isKana = false;
                            continue;

                        default:
                            dataOut[num++] = this.DecodeKana(num5);
                            num2++;
                            continue;
                        }
                    }
                    else
                    {
                        if (num4 == 15U)
                        {
                            this.isKana = false;
                            i          += num6 - 1;
                            continue;
                        }
                        if (num5 == 14U)
                        {
                            i           += num6;
                            dataOut[num] = (this.isKana ? this.DecodeKana(num4) : 165);
                            num++;
                            num2++;
                            this.isKana = true;
                            continue;
                        }
                        if (num5 == 15U)
                        {
                            dataOut[num] = (this.isKana ? this.DecodeKana(num4) : 165);
                            i           += num6;
                            num2++;
                            num++;
                            this.isKana = false;
                            continue;
                        }
                    }
                    if (num + 2 > offsetOut + lengthOut)
                    {
                        break;
                    }
                    if (this.isKana)
                    {
                        dataOut[num]     = this.DecodeKana(num4);
                        dataOut[num + 1] = this.DecodeKana(num5);
                    }
                    else if (num4 >= 128U)
                    {
                        switch (this.ClassifyPair(num4, num5))
                        {
                        case JisX0208PairClass.Unrecognized:
                        case JisX0208PairClass.Cp932:
                            goto IL_37C;

                        case JisX0208PairClass.IbmExtension:
                            break;

                        default:
                            throw new InvalidOperationException("unrecognized pair class, update DecodeJisX0208_1983.DecodeToCp932");

                        case JisX0208PairClass.IbmExtension | JisX0208PairClass.Cp932:
                            if (this.isRunContainsIbmExtension != JisX0208PairClass.IbmExtension)
                            {
                                goto IL_37C;
                            }
                            break;
                        }
                        this.isRunContainsIbmExtension = JisX0208PairClass.IbmExtension;
                        byte b;
                        byte b2;
                        this.MapIbmExtensionToCp932(num4, num5, out b, out b2);
                        dataOut[num]     = b;
                        dataOut[num + 1] = b2;
                        goto IL_413;
IL_37C:
                        dataOut[num]     = (byte)num4;
                        dataOut[num + 1] = (byte)num5;
                    }
                    else
                    {
                        if ((num4 & 1U) == 1U)
                        {
                            num5 += 31U;
                        }
                        else
                        {
                            num5 += 125U;
                        }
                        if (num5 >= 127U)
                        {
                            num5 += 1U;
                        }
                        num4 = (num4 - 33U >> 1) + 129U;
                        if (num4 > 159U)
                        {
                            num4 += 64U;
                        }
                        dataOut[num]     = (byte)num4;
                        dataOut[num + 1] = (byte)num5;
                    }
IL_413:
                    i    += num6;
                    num  += 2;
                    num2 += 2;
                }
            }
            if (!flag && i + 1 == offsetIn + lengthIn)
            {
                this.leftoverByte = dataIn[i++];
            }
            usedIn   = i - offsetIn;
            usedOut  = num2;
            complete = (i == offsetIn + lengthIn);
        }
        // Token: 0x06000B92 RID: 2962 RVA: 0x00069774 File Offset: 0x00067974
        public override ValidationResult GetRunLength(byte[] dataIn, int offsetIn, int lengthIn, Escape escape, out int usedIn, out int usedOut)
        {
            usedIn  = 0;
            usedOut = 0;
            bool flag  = false;
            bool flag2 = false;
            int  i     = offsetIn;
            int  num   = 0;
            int  num2  = 0;
            int  limit = this.CalculateLoopCountLimit(lengthIn);
            byte b     = 0;

            if (escape.IsValidEscapeSequence)
            {
                if (!this.IsEscapeSequenceHandled(escape))
                {
                    throw new InvalidOperationException(string.Format("unhandled escape sequence: {0}", escape.Sequence));
                }
                i += escape.BytesInCurrentBuffer;
                this.runBeganWithEscape = true;
                this.isKana             = false;
                this.leftoverByte       = 0;
            }
            while (i < offsetIn + lengthIn)
            {
                this.CheckLoopCount(ref num2, limit);
                uint num3;
                uint num4;
                int  num5;
                if (this.leftoverByte != 0 && i == offsetIn)
                {
                    num3 = (uint)this.leftoverByte;
                    num4 = (uint)dataIn[i];
                    num5 = 1;
                    b    = this.leftoverByte;
                    this.leftoverByte = 0;
                }
                else if (i + 2 <= offsetIn + lengthIn)
                {
                    num3 = (uint)dataIn[i];
                    num4 = (uint)dataIn[i + 1];
                    num5 = 2;
                }
                else
                {
                    num3 = (uint)dataIn[i];
                    if (num3 == 27U || (!this.runBeganWithEscape && (num3 == 14U || num3 == 15U)) || num3 == 0U)
                    {
                        flag2 = true;
                        break;
                    }
                    if (this.isKana && num3 != 14U && num3 != 15U)
                    {
                        i++;
                        num++;
                        break;
                    }
                    break;
                }
                if (num3 == 27U)
                {
                    flag2 = true;
                    break;
                }
                if (num3 == 0U)
                {
                    flag2 = true;
                    break;
                }
                if (num4 == 27U)
                {
                    if (num3 == 14U || num3 == 15U)
                    {
                        if (this.runBeganWithEscape)
                        {
                            i++;
                        }
                    }
                    else
                    {
                        i++;
                        if (this.isKana)
                        {
                            num++;
                        }
                    }
                    flag2 = true;
                    break;
                }
                if (num4 == 0U)
                {
                    if (num3 == 14U || num3 == 15U)
                    {
                        if (this.runBeganWithEscape)
                        {
                            i++;
                        }
                    }
                    else
                    {
                        i++;
                        if (this.isKana)
                        {
                            num++;
                        }
                    }
                    flag2 = true;
                    break;
                }
                if (!this.runBeganWithEscape)
                {
                    if (num3 == 14U || num3 == 15U || num4 == 14U || num4 == 15U)
                    {
                        flag2 = true;
                        break;
                    }
                }
                else if (num3 == 14U)
                {
                    this.isKana = true;
                    i          += num5;
                    if (num4 != 14U && num4 != 15U)
                    {
                        num++;
                        continue;
                    }
                    continue;
                }
                else
                {
                    if (num3 == 15U)
                    {
                        this.isKana = false;
                        i          += num5 - 1;
                        continue;
                    }
                    if (num4 == 14U)
                    {
                        i += num5;
                        num++;
                        this.isKana = true;
                        continue;
                    }
                    if (num4 == 15U)
                    {
                        this.isKana = false;
                        i          += num5;
                        num++;
                        continue;
                    }
                }
                if (num3 >= 128U)
                {
                    flag = true;
                    if (!this.runBeganWithEscape)
                    {
                        break;
                    }
                    if (this.isRunContainsIbmExtension == JisX0208PairClass.Unrecognized)
                    {
                        JisX0208PairClass jisX0208PairClass = this.ClassifyPair(num3, num4);
                        if (jisX0208PairClass == JisX0208PairClass.IbmExtension)
                        {
                            this.isRunContainsIbmExtension = JisX0208PairClass.IbmExtension;
                        }
                    }
                }
                i   += num5;
                num += 2;
            }
            if (!flag2 && i + 1 == offsetIn + lengthIn)
            {
                i++;
            }
            usedIn  = i - offsetIn;
            usedOut = num;
            if (b != 0)
            {
                this.leftoverByte = b;
            }
            if (!flag || this.runBeganWithEscape)
            {
                return(ValidationResult.Valid);
            }
            return(ValidationResult.Invalid);
        }
Beispiel #7
0
        // Token: 0x06000BA2 RID: 2978 RVA: 0x0006A380 File Offset: 0x00068580
        public override void ConvertToCp932(byte[] dataIn, int offsetIn, int lengthIn, byte[] dataOut, int offsetOut, int lengthOut, bool flush, Escape escape, out int usedIn, out int usedOut, out bool complete)
        {
            usedIn  = 0;
            usedOut = 0;
            int i     = offsetIn;
            int num   = offsetOut;
            int num2  = 0;
            int limit = this.CalculateLoopCountLimit(lengthIn);

            if (escape.IsValidEscapeSequence)
            {
                if (!this.IsEscapeSequenceHandled(escape))
                {
                    throw new InvalidOperationException(string.Format("unhandled escape sequence: {0}", escape.Sequence));
                }
                i += escape.BytesInCurrentBuffer;
            }
            while (i < offsetIn + lengthIn)
            {
                this.CheckLoopCount(ref num2, limit);
                byte b = dataIn[i];
                if (b == 27 || b == 15 || b == 14 || b == 0)
                {
                    break;
                }
                if (num + 1 > offsetOut + lengthOut)
                {
                    string message = string.Format("DecodeUsAsciiToCp932.ConvertToCp932: output buffer overrun, offset {0}, length {1}", offsetOut, lengthOut);
                    throw new InvalidOperationException(message);
                }
                dataOut[num++] = dataIn[i++];
            }
            complete = (i == offsetIn + lengthIn);
            usedIn   = i - offsetIn;
            usedOut  = num - offsetOut;
        }
Beispiel #8
0
 public override bool IsEscapeSequenceHandled(Escape escape)
 {
     return(true);
 }
 public override bool IsEscapeSequenceHandled(Escape escape)
 {
     return(escape.Sequence == EscapeSequence.JisX0201_1976 || escape.Sequence == EscapeSequence.JisX0201K_1976 || escape.Sequence == EscapeSequence.ShiftIn || escape.Sequence == EscapeSequence.ShiftOut);
 }
Beispiel #10
0
        // Token: 0x06000BA1 RID: 2977 RVA: 0x0006A29C File Offset: 0x0006849C
        public override ValidationResult GetRunLength(byte[] dataIn, int offsetIn, int lengthIn, Escape escape, out int usedIn, out int usedOut)
        {
            usedIn  = 0;
            usedOut = 0;
            int  i    = offsetIn;
            int  num  = 0;
            bool flag = false;
            bool isValidEscapeSequence = escape.IsValidEscapeSequence;
            int  num2  = 0;
            int  limit = this.CalculateLoopCountLimit(lengthIn);

            if (isValidEscapeSequence)
            {
                if (!this.IsEscapeSequenceHandled(escape))
                {
                    throw new InvalidOperationException(string.Format("unhandled escape sequence: {0}", escape.Sequence));
                }
                i += escape.BytesInCurrentBuffer;
            }
            while (i < offsetIn + lengthIn)
            {
                this.CheckLoopCount(ref num2, limit);
                byte b = dataIn[i];
                if (b == 27 || b == 15 || b == 14 || (b > 127 && !isValidEscapeSequence) || b == 0)
                {
                    break;
                }
                if ((b < 32 || b > 127) && b != 9 && b != 10 && b != 11 && b != 12 && b != 13)
                {
                    flag = true;
                }
                i++;
                num++;
            }
            usedIn  = i - offsetIn;
            usedOut = num;
            if (!flag || isValidEscapeSequence)
            {
                return(ValidationResult.Valid);
            }
            return(ValidationResult.Invalid);
        }
        public override void ConvertToCp932(byte[] dataIn, int offsetIn, int lengthIn, byte[] dataOut, int offsetOut, int lengthOut, bool flush, Escape escape, out int usedIn, out int usedOut, out bool complete)
        {
            usedIn   = 0;
            usedOut  = 0;
            complete = false;
            int i     = offsetIn;
            int num   = offsetOut;
            int num2  = 0;
            int num3  = 0;
            int limit = this.CalculateLoopCountLimit(lengthIn);

            if (escape.IsValidEscapeSequence)
            {
                if (!this.IsEscapeSequenceHandled(escape))
                {
                    throw new InvalidOperationException(string.Format("unhandled escape sequence: {0}", escape.Sequence));
                }
                i                += escape.BytesInCurrentBuffer;
                this.isKana       = (escape.Sequence == EscapeSequence.JisX0201K_1976 || escape.Sequence == EscapeSequence.ShiftOut);
                this.isEscapeKana = (escape.Sequence == EscapeSequence.JisX0201K_1976);
            }
            while (i < offsetIn + lengthIn)
            {
                this.CheckLoopCount(ref num3, limit);
                byte b = dataIn[i];
                if (b == 27 || b == 0)
                {
                    break;
                }
                if (b == 14)
                {
                    this.isKana = true;
                }
                else if (b == 15)
                {
                    this.isKana = this.isEscapeKana;
                }
                else if (b < 128)
                {
                    if (!this.isKana || b < 33 || b > 95)
                    {
                        dataOut[num] = b;
                    }
                    else
                    {
                        dataOut[num] = b + 128;
                    }
                    num++;
                    num2++;
                }
                else if (b >= 161 && b <= 223)
                {
                    dataOut[num] = b;
                    num++;
                    num2++;
                }
                else if (b == 160)
                {
                    dataOut[num] = 32;
                    num++;
                    num2++;
                }
                else
                {
                    dataOut[num] = 63;
                    num++;
                    num2++;
                }
                i++;
            }
            complete = (i == offsetIn + lengthIn);
            usedIn   = i - offsetIn;
            usedOut  = num2;
        }
        public override ValidationResult GetRunLength(byte[] dataIn, int offsetIn, int lengthIn, Escape escape, out int usedIn, out int usedOut)
        {
            usedIn  = 0;
            usedOut = 0;
            int i     = offsetIn;
            int num   = 0;
            int num2  = 0;
            int limit = this.CalculateLoopCountLimit(lengthIn);

            if (escape.IsValidEscapeSequence)
            {
                if (!this.IsEscapeSequenceHandled(escape))
                {
                    throw new InvalidOperationException(string.Format("unhandled escape sequence: {0}", escape.Sequence));
                }
                i += escape.BytesInCurrentBuffer;
                this.runBeganWithEscape = true;
            }
            else if (!this.runBeganWithEscape)
            {
                return(ValidationResult.Invalid);
            }
            while (i < offsetIn + lengthIn)
            {
                this.CheckLoopCount(ref num2, limit);
                byte b = dataIn[i];
                if (b == 27 || b == 0)
                {
                    break;
                }
                if (b != 14 && b != 15)
                {
                    num++;
                }
                i++;
            }
            usedIn  = i - offsetIn;
            usedOut = num;
            return(ValidationResult.Valid);
        }
Beispiel #13
0
        public override void ConvertToCp932(byte[] dataIn, int offsetIn, int lengthIn, byte[] dataOut, int offsetOut, int lengthOut, bool flush, Escape escape, out int usedIn, out int usedOut, out bool complete)
        {
            usedIn   = 0;
            usedOut  = 0;
            complete = false;
            int i     = offsetIn;
            int num   = offsetOut;
            int num2  = 0;
            int num3  = 0;
            int limit = this.CalculateLoopCountLimit(lengthIn);

            if (escape.IsValidEscapeSequence)
            {
                if (!this.IsEscapeSequenceHandled(escape))
                {
                    throw new InvalidOperationException(string.Format("unhandled escape sequence: {0}", escape.Sequence));
                }
                i += escape.BytesInCurrentBuffer;
            }
            else if (escape.Sequence == EscapeSequence.NotRecognized)
            {
                int num4 = 0;
                while (num4 < escape.BytesInCurrentBuffer && num4 < lengthIn)
                {
                    if (num < offsetOut + lengthOut)
                    {
                        dataOut[num++] = dataIn[i + num4];
                        num2++;
                    }
                    num4++;
                }
                i += escape.BytesInCurrentBuffer;
            }
            else if (escape.Sequence == EscapeSequence.Incomplete)
            {
                i += escape.BytesInCurrentBuffer;
            }
            while (i < offsetIn + lengthIn)
            {
                this.CheckLoopCount(ref num3, limit);
                byte b = dataIn[i];
                if (b == 27 || b == 15 || b == 14 || b == 0)
                {
                    break;
                }
                if (b == 160)
                {
                    if (num + 1 > offsetOut + lengthOut)
                    {
                        break;
                    }
                    dataOut[num++] = 32;
                    i++;
                    num2++;
                }
                else if (((b >= 129 && b <= 159) || (b >= 224 && b <= 252)) && i + 2 <= offsetIn + lengthIn && num + 2 <= offsetOut + lengthOut)
                {
                    dataOut[num++] = dataIn[i++];
                    num2++;
                    byte b2 = dataIn[i];
                    if (b2 == 0)
                    {
                        break;
                    }
                    dataOut[num++] = dataIn[i++];
                    num2++;
                }
                else
                {
                    if (num + 1 > offsetOut + lengthOut)
                    {
                        break;
                    }
                    dataOut[num++] = dataIn[i++];
                    num2++;
                }
            }
            usedIn   = i - offsetIn;
            usedOut  = num2;
            complete = (i == offsetIn + lengthIn);
        }
Beispiel #14
0
 public abstract bool IsEscapeSequenceHandled(Escape escape);
Beispiel #15
0
 // Token: 0x06000BA0 RID: 2976 RVA: 0x0006A28E File Offset: 0x0006848E
 public override bool IsEscapeSequenceHandled(Escape escape)
 {
     return(escape.Sequence == EscapeSequence.Iso646Irv);
 }
Beispiel #16
0
 public abstract ValidationResult GetRunLength(byte[] dataIn, int offsetIn, int lengthIn, Escape escape, out int bytesConsumed, out int bytesProduced);
Beispiel #17
0
        public override ValidationResult GetRunLength(byte[] dataIn, int offsetIn, int lengthIn, Escape escape, out int usedIn, out int usedOut)
        {
            usedIn  = 0;
            usedOut = 0;
            int i     = offsetIn;
            int num   = 0;
            int num2  = 0;
            int limit = this.CalculateLoopCountLimit(lengthIn);

            if (escape.IsValidEscapeSequence)
            {
                if (!this.IsEscapeSequenceHandled(escape))
                {
                    throw new InvalidOperationException(string.Format("unhandled escape sequence: {0}", escape.Sequence));
                }
                i += escape.BytesInCurrentBuffer;
            }
            else if (escape.Sequence == EscapeSequence.NotRecognized)
            {
                i   += escape.BytesInCurrentBuffer;
                num += escape.BytesInCurrentBuffer;
            }
            while (i < offsetIn + lengthIn)
            {
                this.CheckLoopCount(ref num2, limit);
                byte b = dataIn[i];
                if (b == 27 || b == 15 || b == 14 || b == 0)
                {
                    break;
                }
                if (b == 160)
                {
                    i++;
                    num++;
                }
                else
                {
                    if ((b >= 129 && b <= 159) || (b >= 224 && b <= 252))
                    {
                        i++;
                        num++;
                        if (i >= offsetIn + lengthIn || dataIn[i] == 0)
                        {
                            break;
                        }
                    }
                    i++;
                    num++;
                }
            }
            usedIn  = i - offsetIn;
            usedOut = num;
            return(ValidationResult.Valid);
        }