Example #1
0
 public BinaryShiftToken(Token previous,
                         int binaryShiftStart,
                         int binaryShiftByteCount)
    : base(previous)
 {
    this.binaryShiftStart = (short) binaryShiftStart;
    this.binaryShiftByteCount = (short) binaryShiftByteCount;
 }
Example #2
0
 public State(Token token, int mode, int binaryBytes, int bitCount)
 {
    this.token = token;
    this.mode = mode;
    this.binaryShiftByteCount = binaryBytes;
    this.bitCount = bitCount;
    // Make sure we match the token
    //int binaryShiftBitCount = (binaryShiftByteCount * 8) +
    //    (binaryShiftByteCount == 0 ? 0 :
    //     binaryShiftByteCount <= 31 ? 10 :
    //     binaryShiftByteCount <= 62 ? 20 : 21);
    //assert this.bitCount == token.getTotalBitCount() + binaryShiftBitCount;
 }
Example #3
0
 public SimpleToken(Token previous, int totalBitCount, int value, int bitCount)
    : base(previous, totalBitCount)
 {
    this.value = (short) value;
    this.bitCount = (short) bitCount;
 }
Example #4
0
 protected Token(Token previous)
 {
    this.previous = previous;
 }
Example #5
0
 /// <summary>
 /// Create a new state representing this state with a latch to a (not
 /// necessary different) mode, and then a code.
 /// </summary>
 public State latchAndAppend(int mode, int value)
 {
    //assert binaryShiftByteCount == 0;
    int bitCount = this.bitCount;
    Token token = this.token;
    if (mode != this.mode)
    {
       int latch = HighLevelEncoder.LATCH_TABLE[this.mode][mode];
       token = token.add(latch & 0xFFFF, latch >> 16);
       bitCount += latch >> 16;
    }
    int latchModeBitCount = mode == HighLevelEncoder.MODE_DIGIT ? 4 : 5;
    token = token.add(value, latchModeBitCount);
    return new State(token, mode, 0, bitCount + latchModeBitCount);
 }
Example #6
0
 public BitArray toBitArray(byte[] text)
 {
    // Reverse the tokens, so that they are in the order that they should
    // be output
    var symbols = new LinkedList<Token>();
    for (Token token = endBinaryShift(text.Length).token; token != null; token = token.Previous)
    {
       symbols.AddFirst(token);
    }
    BitArray bitArray = new BitArray();
    // Add each token to the result.
    foreach (Token symbol in symbols)
    {
       symbol.appendTo(bitArray, text);
    }
    //assert bitArray.getSize() == this.bitCount;
    return bitArray;
 }
Example #7
0
 /// <summary>
 /// Create the state identical to this one, but we are no longer in
 /// Binary Shift mode.
 /// </summary>
 public State endBinaryShift(int index)
 {
    if (binaryShiftByteCount == 0)
    {
       return this;
    }
    Token token = this.token;
    token = token.addBinaryShift(index - binaryShiftByteCount, binaryShiftByteCount);
    //assert token.getTotalBitCount() == this.bitCount;
    return new State(token, mode, 0, this.bitCount);
 }
Example #8
0
 /// <summary>
 /// Create a new state representing this state, but an additional character
 /// output in Binary Shift mode.
 /// </summary>
 public State addBinaryShiftChar(int index)
 {
    Token token = this.token;
    int mode = this.mode;
    int bitCount = this.bitCount;
    if (this.mode == HighLevelEncoder.MODE_PUNCT || this.mode == HighLevelEncoder.MODE_DIGIT)
    {
       //assert binaryShiftByteCount == 0;
       int latch = HighLevelEncoder.LATCH_TABLE[mode][HighLevelEncoder.MODE_UPPER];
       token = token.add(latch & 0xFFFF, latch >> 16);
       bitCount += latch >> 16;
       mode = HighLevelEncoder.MODE_UPPER;
    }
    int deltaBitCount =
       (binaryShiftByteCount == 0 || binaryShiftByteCount == 31) ? 18 :
          (binaryShiftByteCount == 62) ? 9 : 8;
    State result = new State(token, mode, binaryShiftByteCount + 1, bitCount + deltaBitCount);
    if (result.binaryShiftByteCount == 2047 + 31)
    {
       // The string is as long as it's allowed to be.  We should end it.
       result = result.endBinaryShift(index + 1);
    }
    return result;
 }
Example #9
0
 /// <summary>
 /// Create a new state representing this state, with a temporary shift
 /// to a different mode to output a single value.
 /// </summary>
 public State shiftAndAppend(int mode, int value)
 {
    //assert binaryShiftByteCount == 0 && this.mode != mode;
    Token token = this.token;
    int thisModeBitCount = this.mode == HighLevelEncoder.MODE_DIGIT ? 4 : 5;
    // Shifts exist only to UPPER and PUNCT, both with tokens size 5.
    token = token.add(HighLevelEncoder.SHIFT_TABLE[this.mode][mode], thisModeBitCount);
    token = token.add(value, 5);
    return new State(token, this.mode, 0, this.bitCount + thisModeBitCount + 5);
 }
Example #10
0
      private readonly int totalBitCount; // For debugging purposes, only

      protected Token(Token previous, int totalBitCount)
      {
         this.previous = previous;
         this.totalBitCount = totalBitCount;
      }