gbk_codec 0.3.1+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

The GBK (Chinese Internal Code Specification: China GBK 汉字内码扩展规范编码表) code converter library

Created from GBK standard, generated code converter tables, overwrote converter class of dart. It's a pure dart solution.

Two class for GBK library:

  1. gbk, standard 16-bits codec library
  2. gbk_bytes, gbk byte codec library, for bytes stream

Usage #

deCode and enCode using samples, standard 16-bits library and byte library:

import 'package:gbk_codec/gbk_codec.dart';

main() {
  String text = 'dart GBK code 兩岸猿聲啼不住, chinese simple:轻舟已过万重山.';

  //gbk encode
  List<int> gbkCodes = gbk.encode(text);
  String hex = '';
  gbkCodes.forEach((i) {hex += i.toRadixString(16)+ ' ';});
  print(hex);

  //gbk decode
  String decoded_text = gbk.decode(gbkCodes);
  print(decoded_text);

  //gbk_bytes encode
  List<int> gbk_byteCodes = gbk_bytes.encode(text);
  hex = '';
  gbk_byteCodes.forEach((i) {hex += i.toRadixString(16)+ ' ';});
  print(hex);

  //gbk_bytes decode
  String decoded_bytes_text = gbk_bytes.decode(gbk_byteCodes);
  print(decoded_bytes_text);
}

Here is online page decoding sample:

import 'dart:io';
import 'package:gbk_codec/gbk_codec.dart';

const String URL = 'http://www.creaders.net/about_us.html';

main() {
  HttpClient()
      .getUrl(Uri.parse(URL))
      .then((HttpClientRequest request) {return request.close();})
      .then((response) {
          List<int> full = new List<int>();
          response.listen((data) => full.addAll(data),
                    onDone:() => print(gbk_bytes.decode(full)), 
                    onError:(e) => print);  
      });             
}

Features and bugs #

Please file feature requests and bugs at the [issue tracker][tracker].

0.3.1+3 #

  • update README.md file.

0.3.1+2 #

  • upgrade samples; format dart files by using dartfmt.

0.3.1 #

  • add online web page decoding sample.

0.3.0 #

  • bytes codec of gbk is added.

0.2.0 #

  • overwrite converter class, example passed.

0.1.0 #

  • Initial version, created GBK maps.

example/gbk_codec_example.dart

import 'package:gbk_codec/gbk_codec.dart';

main() {
  String text = 'dart GBK code 兩岸猿聲啼不住, chinese simple:轻舟已过万重山.';

  //gbk encode
  List<int> gbkCodes = gbk.encode(text);
  String hex = '';
  gbkCodes.forEach((i) {hex += i.toRadixString(16)+ ' ';});
  print(hex);

  //gbk decode
  String decoded_text = gbk.decode(gbkCodes);
  print(decoded_text);

  //gbk_bytes encode
  List<int> gbk_byteCodes = gbk_bytes.encode(text);
  hex = '';
  gbk_byteCodes.forEach((i) {hex += i.toRadixString(16)+ ' ';});
  print(hex);

  //gbk_bytes decode
  String decoded_bytes_text = gbk_bytes.decode(gbk_byteCodes);
  print(decoded_bytes_text);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  gbk_codec: ^0.3.1+3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:gbk_codec/gbk_codec.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:gbk_codec/gbk_codec.dart.

Health suggestions

Fix lib/src/converter_gbk.dart. (-1.49 points)

Analysis of lib/src/converter_gbk.dart reported 3 hints:

line 44 col 26: DO use curly braces for all flow control structures.

line 78 col 23: DO use curly braces for all flow control structures.

line 79 col 10: DO use curly braces for all flow control structures.

Fix lib/src/converter_gbk_byte.dart. (-1.49 points)

Analysis of lib/src/converter_gbk_byte.dart reported 3 hints:

line 56 col 10: DO use curly braces for all flow control structures.

line 88 col 23: DO use curly braces for all flow control structures.

line 89 col 10: DO use curly braces for all flow control structures.

Format lib/gbk_codec.dart.

Run dartfmt to format lib/gbk_codec.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/body_element.dart (Run dartfmt to format lib/src/body_element.dart.)
  • lib/src/create_map.dart (Run dartfmt to format lib/src/create_map.dart.)
  • lib/src/gbk_maps.dart (Run dartfmt to format lib/src/gbk_maps.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
html ^0.14.0+2 0.14.0+3
Transitive dependencies
charcode 1.1.2
csslib 0.16.1
path 1.6.4
source_span 1.5.5
term_glyph 1.1.0
Dev dependencies
pedantic ^1.0.0