main function

void main()

Implementation

void main() async {
  //key is single length String (character)
  //value is codeUnit of GBK

  //load html gbk data
  var firstCode = <String>[] ; // = new List<String>();
  await pageBody().then((dom.Element? bodySource) {
    var lines = <String>[];
    bodySource!.querySelectorAll('p').forEach((e) => lines.add(e.outerHtml));
    for (var l in lines){
      if (l.indexOf('0 1 2 3 4 5 6 7 8 9 A B C D E F') > 0){
        l = l.replaceAll('0 1 2 3 4 5 6 7 8 9 A B C D E F', '');
        l = l.replaceAll('&nbsp;', '');
        firstCode.add(l);
        print(l);
        //print(l.indexOf('<p>AA <br>A'));
        if (l.contains('<p>A9 <br>4')) {
          print('---------break point----------------');
          break;
        } //last item
      }
    }
  });
  print(firstCode.length);
  firstCode.forEach((s) => lineReader(s));

  // check
  gbkMap!.forEach((String char, int gbkCode){
    print('$char  gbkCode=${gbkCode.toRadixString(16)}  unitCode:${char.codeUnitAt(0).toRadixString(16)}');
  });

  var sortChar = gbkMap!.keys.toList()..sort();
  var sameKeys = <String>[];
  var last = '\u0200';
  sortChar.forEach((s) {
    if (s == last) sameKeys.add(s);
    last = s;
  });
  print(sameKeys.length);

  var sortUnit = gbkMap!.values.toList()..sort();
  var sameUnits = <int>[];
  var lst = 9999;
  sortUnit.forEach((i) {
    if (i == lst) {
      sameUnits.add(i);
      print('--- find! ${lst.toRadixString(16)}');
    }
    lst = i;
  });
  print(sameUnits.length);
  var look = int.parse('FE66', radix: 16);
  var idn = sameUnits.where((i) => look==i);
  print(idn);


  //outputs
  var json_char_to_gbk =  jsonEncode(gbkMap);
  final file1 = 'json_char_to_gbk.data';
  await File(file1).writeAsString(json_char_to_gbk);
  print(json_char_to_gbk);
  print(gbkMap!.length);

  var reversed_gbkMap = <String, String>{};
  /*
  gbkMap.forEach((s,i) {
    reversed_gbkMap[i]=s;
  });*/

  gbkMap!.forEach((s,intS) {
    reversed_gbkMap[intS.toRadixString(16)]=s[0];
  });

  var json_gbk_to_char =  jsonEncode(reversed_gbkMap);
  final file2 = 'json_gbk_to_char.data';
  await File(file2).writeAsString(json_gbk_to_char);

  print(reversed_gbkMap);
  print(reversed_gbkMap.length);
  //String json_gbk_to_char =  jsonEncode(reversed_gbkMap);
  print(json_gbk_to_char);


}