示例#1
0
文件: DataType.java 项目: inexas/oak
  private static boolean date(Text t) {
    final boolean result;

    // yyyy '/' MM '/' dd

    final int save = t.cursor();
    if (t.consumeAscii(Text.ASCII_0_9)
        && t.consume('/')
        && t.consumeAscii(Text.ASCII_0_9)
        && t.consume('/')
        && t.consumeAscii(Text.ASCII_0_9)) {
      result = true;
    } else {
      result = false;
      t.setCursor(save);
    }

    return result;
  }
示例#2
0
文件: DataType.java 项目: inexas/oak
  private static boolean decPart(Text t) {
    final boolean result;

    // '.' Digits+
    final int save = t.cursor();
    if (t.consume('.') && t.consumeAscii(Text.ASCII_0_9)) {
      result = true;
    } else {
      t.setCursor(save);
      result = false;
    }

    return result;
  }
示例#3
0
文件: DataType.java 项目: inexas/oak
  private static boolean time(Text t) {
    final boolean result;

    // HH ':' mm ( : ss )?

    // Try for HH:mm...
    int reset = t.cursor();
    if (t.consumeAscii(Text.ASCII_0_9) && t.consume(':') && t.consumeAscii(Text.ASCII_0_9)) {
      result = true;
      reset = t.cursor();

      // Try for :ss...
      if (t.consume(':') && t.consumeAscii(Text.ASCII_0_9)) {
        reset = t.cursor();
      }
    } else {
      result = false;
    }

    t.setCursor(reset);

    return result;
  }
示例#4
0
文件: DataType.java 项目: inexas/oak
  private static boolean binary(Text t, List<Object> valueList, DataType requiredType) {
    final boolean result;

    // '0b' [01]+ [zZfF]?
    final int save = t.cursor();
    if (t.consume("0b") && t.consumeAscii(Text.ASCII_0_1)) {
      final String string = t.getString(save + 2);
      final Object value = deriveType(string, requiredType, t, 2);
      valueList.add(value);
      result = true;
    } else {
      t.setCursor(save);
      result = false;
    }

    return result;
  }
示例#5
0
文件: DataType.java 项目: inexas/oak
  /**
   * In Oak it is possible to embed a tab character as an ASCII 8 or as a \t but internally we store
   * this in ASCII. The same goes for newlines and other tables (see the Oak reference). Here we
   * convert external format to internal format.
   *
   * @param source The text to process, may be null. E.g. "Hello\tworld" (with the quotes)
   * @return Return an internal format string.
   */
  @Nullable
  public static String textToInternalFormat(@Nullable String source) throws ParsingException {
    final String result;

    assert source == null
        || source.length() >= 2
            && source.charAt(0) == '"'
            && source.charAt(source.length() - 1) == '"';

    if (source == null) {
      result = null;
    } else {
      final Text t = new Text();
      final char[] ca = source.toCharArray();
      final int length = ca.length - 1; // 1 because remove quotes

      for (int i = 1; i < length; i++) { // 1 because remove quotes
        final char c = ca[i];
        if (c == '\\') {
          if (i == length - 1) {
            error("Invalid text " + source + ", escape at end of line");
          } else {
            i++;
            final char next = ca[i];
            if (next == 't') {
              t.append('\t');
            } else if (next == 'n') {
              t.append('\n');
            } else if (next == '"') {
              t.append('"');
            } else if (next == '\\') {
              t.append('\\');
            } else if (next == 'u') {
              // Unicode, 1-4 hex characters...
              i++;

              final Text hex = new Text();
              hex.append(source);
              hex.setCursor(i);
              final int start = i;
              if (hex.consumeAscii(Text.ASCII_0_F)) {
                final int end = start + Math.min(4, hex.cursor() - start);
                final String string = hex.getString(start, end);
                final char u = (char) Integer.parseInt(string, 16);
                t.append(u);
                i = end - 1;
              } else {
                error("Invalid text " + source + ", incorrect unicode");
              }
            } else {
              error("Invalid text: \\" + next);
            }
          }
        } else {
          t.append(c);
        }
      }
      result = t.toString();
    }

    return result;
  }