decode method

String decode(
  1. String input
)

Decodes a string, resolving all possible entities.

Implementation

String decode(String input) {
  final output = StringBuffer();
  final length = input.length;
  var position = 0;
  var start = position;
  while (position < length) {
    final value = input.codeUnitAt(position);
    if (value == 38) {
      final index = input.indexOf(';', position + 1);
      if (position + 1 < index) {
        final entity = input.substring(position + 1, index);
        final value = decodeEntity(entity);
        if (value != null) {
          output.write(input.substring(start, position));
          output.write(value);
          position = index + 1;
          start = position;
        } else {
          position++;
        }
      } else {
        position++;
      }
    } else {
      position++;
    }
  }
  output.write(input.substring(start, position));
  return output.toString();
}