bytesToUnicode function

Map<int, String> bytesToUnicode()

A function that returns a map of integers to Unicode strings.

Implementation

Map<int, String> bytesToUnicode() {
  /// A function that returns a map of integers to Unicode strings.
  /// It generates a mapping from byte values to Unicode characters, including printable ASCII characters, Spanish characters, and some special characters.
  /// It first generates a list of byte values, creates a second list by copying the first one, and then appends any byte values that are not in the first list to both lists.
  /// It then maps each byte value in the resulting list to its corresponding Unicode character and returns the resulting map.
  final bs = List<int>.from(List.generate(95, (i) => '!'.codeUnitAt(0) + i))
      .followedBy(List.generate(174 - 161 + 1, (i) => '¡'.codeUnitAt(0) + i))
      .followedBy(List.generate(255 - 174 + 1, (i) => '®'.codeUnitAt(0) + i))
      .toList();

  var cs = List<int>.from(bs);
  var n = 0;
  for (var b = 0; b < 256; b++) {
    if (!bs.contains(b)) {
      bs.add(b);
      cs.add(256 + n);
      n = n + 1;
    }
  }

  List<String> tmp = cs.map((x) => String.fromCharCode(x)).toList();

  final result = <int, String>{};
  for (var i = 0; i < bs.length; i++) {
    result[bs[i]] = tmp[i];
  }
  return result;
}