trimRight method

int trimRight ()

Trims all trailing whitespaces.

Returns the number of bits that have been detached.

Implementation

int trimRight() {
  var trimmed = 0;

  while (_children.isNotEmpty && hasTrailingWhitespace) {
    final child = _children.last;
    if (child is TextBits) {
      final _trimmed = child.trimRight();
      if (_trimmed > 0) {
        trimmed += _trimmed;
        if (child.isEmpty) child.detach();
      } else {
        child.detach();
      }
    } else {
      child.detach();
      trimmed++;
    }
  }

  return trimmed;
}