Skip to main content

chinese_codec 0.1.2 copy "chinese_codec: ^0.1.2" to clipboard
chinese_codec: ^0.1.2 copied to clipboard

Pure Dart codecs for Chinese charsets: GB18030 (incl. 4-byte and supplementary planes), GBK, GB2312, Big5 (CP950) and Big5-HKSCS. No native dependencies.

Changelog #

简体中文 | English

0.1.2 #

  • Big5-HKSCS encoding used to pick the HKSCS extension cell whenever a character also had a regular Big5 cell: 兙 came out as 0x92AF, which CP950 / Windows cannot decode. Encoding now prefers the standard Big5 block (lead 0xA1–0xF9) — that character is 0xA259 again. 56 code points were affected; decoding is unchanged.
  • Big5 / Big5-HKSCS encoding now writes the canonical cell for the two characters that CP950 maps twice: 十 → 0xA451, 卅 → 0xA4CA (what Windows, iconv's CP950 and CPython emit) instead of 0xA2CC / 0xA2CE. Decoding either cell still works.
  • Chunked conversion now works: codec.decoder.bind(...), codec.encoder.bind(...) and stream.transform(codec.decoder) used to throw UnsupportedError. Decoding buffers the whole stream (a multi-byte character may straddle two chunks); encoding converts per chunk.
  • Decoding is 2–3× faster, GB18030 encoding up to 8×: the decoder no longer allocates a single-character String per decoded character, the GB18030 encoder no longer writes byte by byte through BytesBuilder, and the reverse lookup tables are a Uint16List instead of a hash map (GBK cold start 2.7 ms → 0.13 ms; up to 1.7 MB → 128 KB per encoding).
  • chineseEncodingByName trims surrounding whitespace and knows more aliases: GB-2312, CP-936, CP-950, X-GBK, GB18030-2000, GB18030-2022.
  • Encoding from dart:convert is re-exported, so List<Encoding> no longer needs a second import.
  • Documented the 11 punctuation cells where Big5 follows Windows CP950 but CPython's big5 does not, and the 11 cells where Big5-HKSCS follows WHATWG but glibc / CPython do not.

0.1.1 #

  • Filled in the API documentation on pub.dev: the constructors of all five codecs plus name / layout / encoder / decoder / decodeStream / toString now spell out their values and behaviour instead of showing a bare signature. It also states that allowInvalid affects decoding only — characters that cannot be encoded always throw FormatException.
  • Fixed decodeStream: Converter does not implement chunked conversion, so the default implementation in dart:convert threw UnsupportedError on the first call. It now reads the whole byte stream before decoding, so multi-byte characters split across two chunks decode correctly.

0.1.0 #

  • First release: encode/decode for GB18030 (1 / 2 / 4 bytes, including the supplementary plane linear area), GBK, GB2312, Big5 (CP950) and Big5-HKSCS.
  • GB18030 follows the 2022 edition: the 19 code point swaps of Annex D, Table D.1 (10 vertical punctuation marks, 8 Han components, U+1E3F ⇄ PUA U+E7C7), aligned entry by entry with ICU's gb18030-2022.ucm.
  • The three GB encodings share one GB18030 double-byte table; GBK / GB2312 differences are expressed as validity bitmaps plus 2 overrides.
  • New Big5-HKSCS: 18,594 cells, including 1,713 supplementary-plane code points (Cantonese, personal and place names). Data comes from WHATWG Encoding Standard's index-big5.txt (Big5 + HKSCS-2008) and was cross-checked against CPython's big5hkscs.
    • Not a superset relationship with Big5 (CP950): the cells are a superset of CP950, but 250 cells map differently (HKSCS repurposed the ETen extension area of kana, Cyrillic and Greek, so 0xC6A1 is "①" rather than "ヾ"). The encoding has to follow the source file.
    • 4 cells are combining characters — "one byte pair, two code points" (0x8862 → U+00CA U+0304). Both directions handle the two code points as a unit, so round trips hold.
  • allowInvalid means the same as utf8.decode(allowMalformed:): invalid bytes become U+FFFD instead of throwing.
  • chineseCodecs / chineseEncodingByName() look encodings up by name (knowing aliases such as CP936, EUC-CN and Big5-HKSCS).
1
likes
160
points
1.62k
downloads

Documentation

API reference

Publisher

verified publisherpub.eltoro.cn

Weekly Downloads

Pure Dart codecs for Chinese charsets: GB18030 (incl. 4-byte and supplementary planes), GBK, GB2312, Big5 (CP950) and Big5-HKSCS. No native dependencies.

Repository
View/report issues

Topics

#encoding #charset #chinese #gbk #big5

License

MIT (license)

More

Packages that depend on chinese_codec