isBracketWrapped method

  1. @useResult
bool isBracketWrapped()

Returns true if this string starts and ends with a matching bracket pair: parentheses, square brackets, curly braces, or angle brackets.

Implementation

@useResult
bool isBracketWrapped() {
  if (length < 2) {
    return false;
  }

  return (startsWith('(') && endsWith(')')) ||
      (startsWith('[') && endsWith(']')) ||
      (startsWith('{') && endsWith('}')) ||
      (startsWith('<') && endsWith('>'));
}