private static void consumeField()

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


  private static void consumeField(ConsumeResult result, CharSequence path, int i) {
    boolean escaped = false;

    // StringBuilder is inefficient and only will be used if there are escapes in the string that we
    // need to skip.
    StringBuilder builder = new StringBuilder();
    int start;
    int end;

    for (start = i, end = i;
        end < path.length()
            && (escaped
                || (path.charAt(end) != SEGMENT_DELIM_CHAR && path.charAt(end) != INDEX_OPEN_CHAR));
        end++) {
      if (!escaped && path.charAt(end) == ESCAPE_CHAR) {
        // Append everything up to this escape, and start the next sequence at the character
        // following.
        builder.append(path, start, end);
        start = end + 1;
        escaped = true;
        continue;
      }

      escaped = false;
    }

    // Append the last sequence, if we are using the string builder.
    if (start > i) {
      builder.append(path, start, end);
    }

    if (escaped) {
      throw new VerifyException(String.format("Field had trailing %s in %s", ESCAPE_CHAR, path));
    }

    result.seg = new Field(start == i ? path.subSequence(i, end).toString() : builder.toString());
    result.nextI = end;
  }