Example #1
0
  public static int parseUInt(byte separator, Buffer buffer, MutableInt offset, int end) {
    int start = offset.get();
    int off = start;

    checkBounds(IntType.MIN_LENGTH + SEPARATOR_LENGTH, end - off);

    byte b = buffer.getByte(off++);
    long value = digit(b);
    if (!isDigit(b)) throwUnexpectedByte(b);

    do {
      b = buffer.getByte(off++);
      if (isDigit(b)) {
        value = (value << 3) + (value << 1) + digit(b);
      } else if (b == separator) {
        int digits = off - start - SEPARATOR_LENGTH;
        checkUInt(value, digits);
        offset.set(off);
        return (int) value;
      } else {
        throwUnexpectedByte(b);
      }
    } while (off < end);

    throw throwSeparatorNotFound(separator);
  }
Example #2
0
 protected static int parse4DigitUInt(Buffer buffer, int offset) {
   int value = ParserUtil.checkDigit(buffer.getByte(offset));
   value = (value << 3) + (value << 1) + ParserUtil.checkDigit(buffer.getByte(offset + 1));
   value = (value << 3) + (value << 1) + ParserUtil.checkDigit(buffer.getByte(offset + 2));
   value = (value << 3) + (value << 1) + ParserUtil.checkDigit(buffer.getByte(offset + 3));
   return value;
 }
Example #3
0
  public static int parseInt(byte separator, Buffer buffer, MutableInt offset, int end) {
    int off = offset.get();
    checkBounds(SIGN_LENGTH, end - off);

    if (buffer.getByte(off) == '-') {
      offset.set(off + SIGN_LENGTH);
      return -parseUInt(separator, buffer, offset, end);
    } else {
      return parseUInt(separator, buffer, offset, end);
    }
  }