Exemple #1
0
 // Create a new state representing this state, with a temporary shift
 // to a different mode to output a single value.
 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);
 }
Exemple #2
0
 // Create a new state representing this state with a latch to a (not
 // necessary different) mode, and then a code.
 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);
 }
Exemple #3
0
 final State latchAndAppend(int i, int j) {
   int l = bitCount;
   Token token2 = token;
   int k = l;
   Token token1 = token2;
   if (i != mode) {
     k = HighLevelEncoder.LATCH_TABLE[mode][i];
     token1 = token2.add(0xffff & k, k >> 16);
     k = l + (k >> 16);
   }
   if (i == 2) {
     l = 4;
   } else {
     l = 5;
   }
   return new State(token1.add(j, l), i, 0, k + l);
 }
Exemple #4
0
 final State shiftAndAppend(int i, int j) {
   Token token1 = token;
   byte byte0;
   if (mode == 2) {
     byte0 = 4;
   } else {
     byte0 = 5;
   }
   return new State(
       token1.add(HighLevelEncoder.SHIFT_TABLE[mode][i], byte0).add(j, 5),
       mode,
       0,
       bitCount + byte0 + 5);
 }
Exemple #5
0
  /**
   * Lex a sub token: e.g. something like "1,2,3-6" into a token string and set up ready for parsing
   */
  private void lex(String subToken) throws ParsingException {
    // Lex a token stream...
    final List<Token> tokenStreamList = new ArrayList<Token>();
    final char[] ca = subToken.toCharArray();
    Token numberToken = null;
    for (final char c : ca) {
      switch (c) {
        case '*':
          tokenStreamList.add(Token.STAR);
          numberToken = null;
          break;
        case '-':
          tokenStreamList.add(Token.MINUS);
          numberToken = null;
          break;
        case '/':
          tokenStreamList.add(Token.SLASH);
          numberToken = null;
          break;
        case ',':
          tokenStreamList.add(Token.COMMA);
          numberToken = null;
          break;
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          if (numberToken == null) {
            numberToken = new Token(TokenType.NUMBER);
            tokenStreamList.add(numberToken);
          }
          numberToken.add(c);
          break;
        default:
          throw new ParsingException("Invalid character '" + c + "' in token");
      }
    }

    // Set up ready for parser...
    tokenStream = tokenStreamList.toArray(new Token[tokenStreamList.size()]);
    nextToken = 0;
    length = tokenStream.length;
  }
Exemple #6
0
 public static JSONObject login(String username, String validateNum, String deviceId) {
   JSONObject items = new JSONObject();
   boolean rs = false;
   if (!username.equals("") && !validateNum.equals("") && !deviceId.equals("")) {
     // status 0=初始化 1=正常
     Record user =
         Db.findFirst(
             "SELECT bu.*,fur.content AS roleValue,fus.content AS sexValue FROM b_user AS bu LEFT JOIN f_user_role AS fur ON bu.role = fur.id LEFT JOIN f_user_sex AS fus ON bu.sex = fus.id WHERE bu.username = ? AND bu.validateNum = ? AND bu.status < 2",
             username,
             validateNum);
     Long nowTime = System.currentTimeMillis();
     // validate时会初始化b_user 这里null 一定有误
     if (user != null) {
       if ((nowTime - user.getTimestamp("validateTime").getTime()) < 300000) {
         Db.update(
             "UPDATE b_user SET validateNum = ? , status = 1 WHERE username = ?",
             "----",
             user.getStr("username"));
         items.put("user", user.toJson());
         String agentToken = Token.add(username, deviceId);
         items.put("agentToken", agentToken);
         Record auth =
             Db.findFirst(
                 "SELECT * FROM b_auth WHERE username = ? AND role = ?",
                 username,
                 user.getInt("role"));
         if (auth != null) {
           items.put("auth", auth.toJson());
         } else {
           auth = new Record();
           auth.set("username", username).set("role", user.getInt("role")).set("status", 0);
           boolean authRs = Db.save("b_auth", auth);
           if (authRs) {
             items.put("auth", auth.toJson());
           }
         }
         rs = true;
       }
     }
   }
   items.put("rs", rs);
   return items;
 }
Exemple #7
0
 // Create a new state representing this state, but an additional character
 // output in Binary Shift mode.
 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;
 }
Exemple #8
0
 final State addBinaryShiftChar(int i) {
   Object obj;
   int k;
   int l;
   label0:
   {
     Token token1 = token;
     int i1 = mode;
     int j = bitCount;
     if (mode != 4) {
       l = j;
       k = i1;
       obj = token1;
       if (mode != 2) {
         break label0;
       }
     }
     k = HighLevelEncoder.LATCH_TABLE[i1][0];
     obj = token1.add(0xffff & k, k >> 16);
     l = j + (k >> 16);
     k = 0;
   }
   State state;
   byte byte0;
   if (binaryShiftByteCount == 0 || binaryShiftByteCount == 31) {
     byte0 = 18;
   } else if (binaryShiftByteCount == 62) {
     byte0 = 9;
   } else {
     byte0 = 8;
   }
   state = new State(((Token) (obj)), k, binaryShiftByteCount + 1, l + byte0);
   obj = state;
   if (state.binaryShiftByteCount == 2078) {
     obj = state.endBinaryShift(i + 1);
   }
   return ((State) (obj));
 }