decodeEntity method Null safety

  1. @override
String? decodeEntity(
  1. String input
)
override

Decodes a single character entity, returns the decoded entity or null if the input is invalid.

Implementation

@override
String? decodeEntity(String input) {
  if (input.length > 1 && input[0] == '#') {
    if (input.length > 2 && (input[1] == 'x' || input[1] == 'X')) {
      // Hexadecimal character reference.
      return String.fromCharCode(int.parse(input.substring(2), radix: 16));
    } else {
      // Decimal character reference.
      return String.fromCharCode(int.parse(input.substring(1)));
    }
  } else {
    // Named character reference.
    return entities[input];
  }
}