strip static method

String strip(
  1. String text
)

Removes extra whitespace

Implementation

static String strip(String text) {
  var hasSpaceAfter = false;
  var hasSpaceBefore = false;
  if (text.startsWith(" ")) {
    hasSpaceBefore = true;
  }
  if (text.endsWith(" ")) {
    hasSpaceAfter = true;
  }
  text = text.trim();
  if (hasSpaceBefore) text = " " + text;
  if (hasSpaceAfter) text = text + " ";
  return text;
}