Ejemplo n.º 1
0
        // Create a new state representing this state, but an additional character
        // output in Binary Shift mode.
        public State AddBinaryShiftChar(int index)
        {
            IToken       tokens   = Tokens;
            EncodingMode mode     = Mode;
            int          bitCount = BitCount;

            if (Mode == EncodingMode.Punct || Mode == EncodingMode.Digit)
            {
                var latch = LatchTable[Mode][EncodingMode.Upper];
                tokens    = new SimpleToken(tokens, latch & 0xFFFF, (byte)(latch >> 16));
                bitCount += (int)(latch >> 16);
                mode      = EncodingMode.Upper;
            }

            int deltaBitCount = 8;

            if (ShiftByteCount == 0 || ShiftByteCount == 31)
            {
                deltaBitCount = 18;
            }
            else if (ShiftByteCount == 62)
            {
                deltaBitCount = 9;
            }

            var result = new State(mode, tokens, ShiftByteCount + 1, bitCount + deltaBitCount);

            if (result.ShiftByteCount == 2047 + 31)
            {
                // The string is as long as it's allowed to be.  We should end it.
                result = result.EndBinaryShift(index + 1);
            }

            return(result);
        }
Ejemplo n.º 2
0
        // Create a new state representing this state, with a temporary shift
        // to a different mode to output a single value.
        public State ShiftAndAppend(EncodingMode mode, uint value)
        {
            IToken tokens = Tokens;

            // Shifts exist only to UPPER and PUNCT, both with tokens size 5.
            tokens = new SimpleToken(tokens, ShiftTable[Mode][mode], Mode.BitCount());
            tokens = new SimpleToken(tokens, value, 5);

            return(new State(Mode, tokens, 0, BitCount + Mode.BitCount() + 5));
        }
Ejemplo n.º 3
0
        // Create a new state representing this state with a latch to a (not
        // necessary different) mode, and then a code.
        public State LatchAndAppend(EncodingMode mode, uint value)
        {
            int    bitCount = BitCount;
            IToken tokens   = Tokens;

            if (mode != Mode)
            {
                uint latch = LatchTable[Mode][mode];
                tokens    = new SimpleToken(tokens, latch & 0xFFFF, (byte)(latch >> 16));
                bitCount += (int)(latch >> 16);
            }

            tokens = new SimpleToken(tokens, value, mode.BitCount());

            return(new State(mode, tokens, 0, bitCount + mode.BitCount()));
        }