private static void consumeBracketted()

in runtime/src/main/java/com/google/cloud/verticals/foundations/dataharmonization/data/path/Path.java [164:195]


  private static void consumeBracketted(ConsumeResult result, CharSequence path, int i) {
    i++; // Skip [
    int start = i;
    int end = i;
    boolean isIndex = true;
    for (; i < path.length() && path.charAt(i) != INDEX_CLOSE_CHAR; i++) {
      end = i + 1;
      isIndex = isIndex && Character.isDigit(path.charAt(i));
    }

    CharSequence content = path.subSequence(start, end);
    if (i >= path.length() || path.charAt(i) != INDEX_CLOSE_CHAR) {
      throw new VerifyException(
          String.format(
              "Expected %s after %s in %s, found %s",
              INDEX_CLOSE_CHAR,
              content,
              path,
              i >= path.length() ? "the end of the path" : path.subSequence(i, i + 1)));
    }

    Integer index = null;
    String field = "";
    if (content.length() > 0 && isIndex) {
      index = Integer.parseInt(content, 0, content.length(), 10);
    } else if (content.length() > 0) {
      field = content.toString();
    }
    i++; // Skip ]
    result.seg = isIndex ? new Index(index) : new Field(field);
    result.nextI = i;
  }