tryParse static method

EscapeSequence? tryParse(
  1. String string
)

Parses an escape sequence from the given string.

If the string is not a CSI escape sequence, returns null.

Implementation

static EscapeSequence? tryParse(String string) {
  final match = _csiEscape.firstMatch(string);
  if (match == null) {
    return null;
  }

  var params = match.group(1);
  var prefix = '';
  if (params != null && params.startsWith('?')) {
    prefix = params[0];
    params = params.substring(1);
  }
  if (params == '') {
    params = null;
  }

  return _EscapeSequence(
    match.group(2)!,
    prefix: prefix,
    parameters: params?.split(';').map(int.parse) ?? const [],
  );
}