trim method

StringView trim()

Trims leading and trailing whitespace, returning a new tightly-bound StringView.

Implementation

StringView trim() {
  int newStart = _start;
  int newEnd = _end;
  while (newStart < newEnd && _isWhitespace(_string[newStart])) {
    newStart++;
  }
  while (newEnd > newStart && _isWhitespace(_string[newEnd - 1])) {
    newEnd--;
  }
  return StringView.substring(_string, newStart, newEnd);
}