charcode 0.1.5

Character encoding conversion implementing the WHATWG Encoding Standard, with no external dependencies.
Documentation
[package]
name = "charcode"
version = "0.1.5"
edition = "2024"
rust-version = "1.88"
license = "MIT"
description = "Character encoding conversion implementing the WHATWG Encoding Standard, with no external dependencies."
repository = "https://github.com/KarpelesLab/charcode"
documentation = "https://docs.rs/charcode"
readme = "README.md"
keywords = ["encoding", "charset", "utf-8", "unicode", "conversion"]
categories = ["encoding", "text-processing", "no-std"]
exclude = ["/tools", "/.github"]

[dependencies]
serde = { version = "1", optional = true, default-features = false }

[dev-dependencies]
serde_json = "1"

[features]
default = ["std", "whatwg"]

# --- capabilities -----------------------------------------------------------
# Implements `std::error::Error` for the error types.  Implies `alloc`.
std = ["alloc"]
# The conveniences that hand back an owned `String`, `Vec` or `Cow`.  Turning it
# off leaves the streaming API, which converts into caller-provided buffers and
# never allocates.
alloc = []
# An encoding serializes as its name.  Needs neither `std` nor `alloc`.
serde = ["dep:serde"]
# The `charcode` command-line tool, an iconv-style converter (gates the binary
# target below).  It adds no dependencies.
# The tool supports //TRANSLIT, so it takes that table; the library does not.
cli = ["std", "whatwg", "translit"]

# --- the WHATWG Encoding Standard -------------------------------------------
# Everything the standard defines: all 40 encodings and all 228 of their labels.
whatwg = [
    "whatwg-aliases",
    "single-byte",
    "big5",
    "euc-jp",
    "euc-kr",
    "gb18030",
    "iso-2022-jp",
    "shift-jis",
]
# `Encoding::for_whatwg_label`, the standard's `get an encoding`, which answers
# only with encodings the standard defines however many of the extra groups
# below are compiled in.  Independent of which tables you take, so a build that
# needs only Japanese and Unicode can pair this with `shift-jis`, `euc-jp` and
# `iso-2022-jp`.
whatwg-aliases = []

# --- table groups -----------------------------------------------------------
# UTF-8, UTF-16BE/LE, replacement and x-user-defined are always present: they
# need no tables, and the first three are what byte order mark sniffing
# resolves to.
#
# The standard's 28 legacy single-byte encodings, about 22 KiB of tables.
single-byte = ["half-byte"]

# Two internal features, enabled automatically by the groups that need them.
# Neither is meant to be selected directly.
#
# The decoder for an encoding whose bytes below 0x80 are plain ASCII, so only
# the 128 above need a table.
half-byte = []
# The decoder for one whose whole byte range needs a table, such as EBCDIC.
full-byte = []
# The legacy multi-byte encodings, one feature each because their tables are
# the large ones.
big5 = []          # ~170 KiB
euc-jp = []        # ~70 KiB, shares the JIS tables with the two below
euc-kr = []        # ~115 KiB
gb18030 = []       # ~145 KiB, also provides GBK
iso-2022-jp = []   # ~55 KiB
# Reuses the EUC-KR table, so it needs that group.  The standard refuses this
# encoding outright; `for_whatwg_label` still answers `replacement` for it.
iso-2022-kr = ["euc-kr"]
# Brings its own CNS 11643 planes 1 and 2, about 90 KiB, and takes GB 2312 from
# the gb18030 group.  Refused by the standard in the same way.
iso-2022-cn = ["gb18030"]  # ~90 KiB
# RFC 1554, which designates six sets: it needs the tables of all of them, and
# brings none of its own.
iso-2022-jp-2 = ["euc-jp", "euc-kr", "gb18030", "single-byte"]
# UTS #6, which is a compression scheme rather than a charset.  No tables: its
# eight windows move over Unicode instead.
scsu = []
shift-jis = []     # ~55 KiB

# --- charsets outside the standard ------------------------------------------
# All off by default.  Their labels never collide with one the standard defines,
# so enabling them cannot change what an existing lookup resolves to.
#
# Everything below at once.
extras = ["dos", "ebcdic", "mac", "misc", "unicode-extras"]
# IBM PC / OEM code pages: 437, 737, 775, 850, 852, 855, 856, 857, 860-865, 869,
# 1006.  About 13 KiB.
dos = ["full-byte", "half-byte"]
# IBM mainframe EBCDIC: 037, 424, 500, 875, 1026.  About 6 KiB.
ebcdic = ["full-byte"]
# Apple's regional variants of Mac OS Roman: Arabic, Celtic, Central European,
# Croatian, Farsi, Gaelic, Greek, Icelandic, Romanian, Turkish.  About 8 KiB.
mac = ["half-byte"]
# Atari ST and KZ-1048.  About 2 KiB.
misc = ["half-byte"]
# Best-effort ASCII transliteration for the encoders: `EncodeOptions::transliterate`.
# About 30 KiB of table, derived from Unicode's decompositions.
translit = []
# UTF-32BE/LE and UTF-7.  No tables at all; these are algorithmic.  The standard
# leaves UTF-7 out deliberately, and `Encoding::for_whatwg_label` will not return
# it however this is set.
unicode-extras = []

[[bin]]
name = "charcode"
path = "src/bin/charcode/main.rs"
required-features = ["cli"]

# A plain `fn main()` rather than a harness, so benchmarking needs no dependency.
[[bench]]
name = "throughput"
harness = false
required-features = ["whatwg"]

[package.metadata.docs.rs]
all-features = true

[profile.release]
opt-level = 3