expectChar method

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

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

If character is a Unicode code point in a supplementary plane, this will consume two code units. Dart's string representation is UTF-16, which represents supplementary-plane code units as two code units.

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);
}