guessEncoding static method

String guessEncoding(
  1. Uint8List bytes,
  2. DecodeHint? hints
)

@param bytes bytes encoding a string, whose encoding should be guessed @param hints decode hints if applicable @return name of guessed encoding; at the moment will only guess one of: "SJIS", "UTF8", "ISO8859_1", or the platform default encoding if none of these can possibly be correct

Implementation

static String guessEncoding(
  Uint8List bytes,
  DecodeHint? hints,
) {
  final c = guessCharset(bytes, hints);
  if (c?.name == shiftJisCharset.name) {
    return 'SJIS';
  }
  if (c?.name == utf8.name) {
    return 'UTF8';
  }
  if (c?.name == latin1.name) {
    return 'ISO8859_1';
  }
  return c!.name;
}