chinese_codec 0.1.2
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 as0x92AF, which CP950 / Windows cannot decode. Encoding now prefers the standard Big5 block (lead0xA1–0xF9) — that character is0xA259again. 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 of0xA2CC/0xA2CE. Decoding either cell still works. - Chunked conversion now works:
codec.decoder.bind(...),codec.encoder.bind(...)andstream.transform(codec.decoder)used to throwUnsupportedError. 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
Stringper decoded character, the GB18030 encoder no longer writes byte by byte throughBytesBuilder, and the reverse lookup tables are aUint16Listinstead of a hash map (GBK cold start 2.7 ms → 0.13 ms; up to 1.7 MB → 128 KB per encoding). chineseEncodingByNametrims surrounding whitespace and knows more aliases:GB-2312,CP-936,CP-950,X-GBK,GB18030-2000,GB18030-2022.Encodingfromdart:convertis re-exported, soList<Encoding>no longer needs a second import.- Documented the 11 punctuation cells where Big5 follows Windows CP950 but CPython's
big5does 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/toStringnow spell out their values and behaviour instead of showing a bare signature. It also states thatallowInvalidaffects decoding only — characters that cannot be encoded always throwFormatException. - Fixed
decodeStream:Converterdoes not implement chunked conversion, so the default implementation indart:convertthrewUnsupportedErroron 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'sbig5hkscs.- 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
0xC6A1is "①" 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.
- 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
allowInvalidmeans the same asutf8.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).