Something went wrong. Try again.
Converting between UTF-8 and legacy character encodings, as the WHATWG Encoding Standard and glibc's iconv define them.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! Converting between UTF-8 and the legacy character encodings, as the WHATWG//! Encoding Standard defines them.//!//! Forty encodings: windows-1252 and the rest of the single-byte ones,//! Shift_JIS, EUC-JP, ISO-2022-JP, GBK, gb18030, Big5, EUC-KR, UTF-16 in both//! byte orders, and UTF-8 itself. That is the list browsers implement and,//! deliberately, no more -- the standard is a closed set, and the reason is//! that a label a server and a client disagree about is an attack rather than//! a feature.//!//! Four EBCDIC code pages come with it, as a type of their own rather than as//! members of `Encoding`, so that closed set stays closed: see `ebcdic.zig`.//!//! Decoding never fails by default: a byte sequence that means nothing//! becomes U+FFFD, which is what makes a document with one bad byte in it//! still a document. Ask for `.fatal` when the input is a checked format//! rather than prose.//!//! ```zig//! const charset = @import("charset");//!//! const utf8 = try charset.decodeAlloc(gpa, .shift_jis, bytes, .{});//! defer gpa.free(utf8);//!//! const encoding = charset.Encoding.fromLabel("Shift-JIS").?;//! ```//!//! For text arriving in pieces, `Decoder` and `Encoder` keep the state that a//! character split across two chunks needs.//!//! The mapping tables under `src/tables/` are generated from the index files//! the standard publishes, which are committed in `data/`; `zig build//! gen-tables` remakes them.
const convert = @import("convert.zig");
pub const Decoder = @import("Decoder.zig");pub const Encoder = @import("Encoder.zig");pub const Encoding = @import("encoding.zig").Encoding;
/// EBCDIC, which the Encoding Standard does not define and which is/// deliberately not an `Encoding`: the standard's set is closed, and/// `Encoding.fromLabel` refusing everything outside it is a property worth/// keeping. Reached by naming a code page in code, never by a label off a/// header.pub const ebcdic = @import("ebcdic.zig");pub const Ebcdic = ebcdic.CodePage;
/// Byte order marks, which are not part of any encoding here but decide/// which one to use.pub const bom = @import("bom.zig");
pub const DecodeError = convert.DecodeError;pub const EncodeError = convert.EncodeError;pub const EncodeEbcdicError = convert.EncodeEbcdicError;
pub const decodeAlloc = convert.decodeAlloc;pub const decodeBomAlloc = convert.decodeBomAlloc;pub const encodeAlloc = convert.encodeAlloc;pub const decodeEbcdicAlloc = convert.decodeEbcdicAlloc;pub const encodeEbcdicAlloc = convert.encodeEbcdicAlloc;
test { @import("std").testing.refAllDecls(@This()); _ = @import("byte_table.zig"); _ = @import("codec.zig"); _ = @import("codecs.zig"); _ = @import("index.zig");}