/** * Start at the given nesting level - read lines until you get to line with equal to or greater * than the current one. */ public static String[] getArtifactLines(Pointer startingIndex, String... lines) { List<String> lineList = new ArrayList<>(); int index = startingIndex.getIndex(); String topLine = lines[index]; lineList.add( topLine); // add the line which defines this object - all others, if they exist, are // children. int nestingLevel = parseNestingLevel(topLine); for (int i = index + 1; i < lines.length; i++) { String line = lines[i]; // we return if the nesting level of the line in question is the same as the "parent" level int childNestingLevel = parseNestingLevel(line); if (childNestingLevel == nestingLevel) { startingIndex.increment(lineList.size()); // return new array of startIndex to i return lineList.toArray(new String[lineList.size()]); } else { lineList.add(line); } } startingIndex.increment(lineList.size()); return lineList.toArray(new String[lineList.size()]); }