expectChar method Null safety

void expectChar(
  1. int character,
  2. {String? name}
)

If the next character in the string is character, consumes it.

If character could not be consumed, throws a FormatException describing the position of the failure. name is used in this error as the expected name of the character being matched; if it's null, the character itself is used instead.

Implementation

void expectChar(int character, {String? name}) {
  if (scanChar(character)) return;

  if (name == null) {
    if (character == $backslash) {
      name = r'"\"';
    } else if (character == $doubleQuote) {
      name = r'"\""';
    } else {
      name = '"${String.fromCharCode(character)}"';
    }
  }

  _fail(name);
}