decodeAnyText static method

String decodeAnyText(
  1. String text,
  2. String? transferEncoding,
  3. String? charset
)

Decodes the given text

Implementation

static String decodeAnyText(
  final String text,
  final String? transferEncoding,
  final String? charset,
) {
  final transferEnc = transferEncoding ?? contentTransferEncodingNone;
  final decoder = _textDecodersByName[transferEnc.toLowerCase()];
  if (decoder == null) {
    print('Error: no decoder found for '
        'content-transfer-encoding [$transferEnc].');

    return text;
  }
  final cs = charset ?? 'utf8';
  final codec = _charsetCodecsByName[cs.toLowerCase()]?.call();
  if (codec == null) {
    print('Error: no encoding found for charset [$cs].');

    return text;
  }

  return decoder(text, codec, isHeader: false);
}