toString method

  1. @override
String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation

@override
String toString() {
  if (input case final String input) {
    if (pos >= input.length) {
      return '$ok $pos:';
    }

    var length = input.length - pos;
    length = length > 40 ? 40 : length;
    final string = input.substring(pos, pos + length);
    return '$ok $pos:$string';
  } else if (input case final ChunkedParsingSink input) {
    final source = input.data;
    final pos = this.pos - input.start;
    if (pos < 0 || pos >= source.length) {
      return '$ok $pos:';
    }

    var length = source.length - pos;
    length = length > 40 ? 40 : length;
    final string = source.substring(pos, pos + length);
    return '$ok $pos:$string';
  }

  return super.toString();
}