contentBetweenBrackets property

List<String> get contentBetweenBrackets

List of all characters between opening and closing bracket.

Example: [1,2,3,4,4,6,8,1,0,1,1], "anotherKey": []

ContentBetweenBrackets == [1,2,3,4,4,6,8,1,0,1,1].

Implementation

List<String> get contentBetweenBrackets {
  _totalDepth = 1;

  final subList = characters.sublist(
    startIndex,
    characters.length,
  );

  var countTotalDepth = true;

  var index = startIndex;

  String token;

  var depth = 1;

  while (depth != 0) {
    index += 1;
    token = characters[index];

    if (token == openingBracket) {
      depth += 1;

      if (countTotalDepth) {
        _totalDepth += 1;
      }
    }

    if (token == closingBracket) {
      depth -= 1;
      countTotalDepth = false;
    }
  }

  _endIndex = index;
  return subList.sublist(0, index);
}