From 2b2c1fb692836adf47b474fb2f4995fa763f4585 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Tue, 9 Jun 2026 08:24:00 +0200 Subject: [PATCH] feat(parsing): full GB18030 four-byte sequences Extend the GBK two-byte subset to full GB18030: a lead byte followed by a digit opens a four-byte form whose pointer is mapped through the WHATWG index-gb18030-ranges linear ranges, reaching the supplementary planes. The 207 ranges are vendored verbatim. Wired into the whole-buffer and streaming decoders and the encoding-name table (gb18030/gb-18030). Closes #102 --- CHANGELOG.md | 1 + README.md | 4 +- Sources/Parsing/ByteDecoder.swift | 2 + Sources/Parsing/GB18030Decoder.swift | 94 ++++++++++++++++++++++++++ Sources/Parsing/GB18030Ranges.swift | 52 ++++++++++++++ Sources/Parsing/InputEncoding.swift | 1 + Sources/Parsing/StreamingDecoder.swift | 25 +++++++ Tests/EncodingTests.swift | 12 ++++ 8 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 Sources/Parsing/GB18030Decoder.swift create mode 100644 Sources/Parsing/GB18030Ranges.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index d644f57..00753e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Full GB18030 (#102): the byte decoder gains the GB18030 four-byte sequences on top of the GBK two-byte subset, for both the whole-buffer and streaming decoders, selected by the `gb18030` declaration name. A lead in `0x81`-`0xFE` followed by a digit opens a four-byte form whose pointer is mapped through the WHATWG `index-gb18030-ranges` linear ranges, reaching the supplementary planes (the `189000` range maps to `U+10000` and beyond). The 207 ranges are vendored verbatim from the WHATWG `index-gb18030-ranges.txt`. GB18030 is China's mandatory standard, supported in libxml2 through iconv. - CJK multi-byte encodings (#99, in progress): the byte decoder gains a multi-byte path and the WHATWG **Shift-JIS** and **EUC-JP** algorithms, for both the whole-buffer and streaming decoders, selected by the XML declaration's `encoding` name. Shift-JIS covers ASCII, half-width katakana, and the JIS X 0208 plane; EUC-JP adds the `0x8E` half-width katakana and `0x8F` JIS X 0212 leads. EUC-KR (CP949/UHC) decodes Hangul and Hanja through the WHATWG `index-euc-kr`, and GBK (which also covers GB2312) decodes Chinese through the two-byte range of `index-gb18030` with `0x80` as the euro sign. The JIS X 0208/0212, CP949, and GBK indexes are all vendored verbatim from the corresponding WHATWG `index-*.txt` files. This completes the CJK multi-byte encodings. - HTML named character references: the complete WHATWG named character reference set (#84), all 2,125 semicolon-form references including the astral mathematical alphanumerics and the 93 two-codepoint references, vendored verbatim from the authoritative `entities.json` (replacing the previous 16-entry stopgap). Decoding stays longest-match with an optional trailing semicolon, on top of the existing numeric-reference validation. - HTML5 select content model (#83, stage 10): a `` closes the open one rather than nesting, and an ``/``/`